#include #include #include #define STDIN 0 /* file descriptor for standard input */ main() { struct timeval tv; fd_set readfds; tv.tv_sec = 10; tv.tv_usec = 500000; FD_ZERO(&readfds); FD_SET(STDIN, &readfds); /* don't care about writefds and exceptfds: */ puts("here"); select(STDIN+1, &readfds, NULL, NULL, &tv); puts("there"); if (FD_ISSET(STDIN, &readfds)) { printf("A key was pressed!\n"); } else printf("Timed out.\n"); }