Забыли упомянуть классику жанра.
#include <sys/select.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv) {
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 500;
int n = select(0, NULL, NULL, NULL, &tv);
if (n < 0) {
perror("select");
return (EXIT_FAILURE);
}
if (n == 0) {
printf("timeout\n");
return (EXIT_SUCCESS);
}
if (n > 0) {
printf("ahtung O_o\n");
return (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}