/* According to POSIX 1003.1-2001 */ #include <sys/select.h> /* According to earlier standards */ #include <sys/time.h> #include <sys/types.h> #include <unistd.h> #include <stdio.h> int main (int argc, char* argv[]) { struct timeval tv; fd_set read_fd; do{ printf("iterating - press [ENTER] to stop\n"); // control for key pressed (1 second timeout) // tv vals can be set to 0 for test and return tv.tv_sec=1; tv.tv_usec=0; FD_ZERO(&read_fd); FD_SET(STDIN_FILENO,&read_fd); }while (select(1, &read_fd, NULL, NULL, &tv)!=1); // read the [ENTER] to avoid console double echo (that's optional) char key; read(STDIN_FILENO,&key,1); }