C - how to poll() input without buffering?
问题 I am trying to detect any character typed to stdin (without a newline character). I tried : setvbuf(stdin, NULL, _IONBF); //This returns 0 struct pollfd pfd = {STDIN_FILENO, POLLIN}; while (!poll(pfd, 1, ms)) { /* do some thing, e.g. printf("n\n"); */ } It appears not stop printing when I typed q , but did stop after I hit enter . The system I am working on is arch-linux, compiler is gcc. 回答1: The q is being held up in the kernel's TTY layer driver/buffer because it is in "cooked" mode. In