#include #include #include #include int main() { fd_set rfds; struct timeval tv; int retval,n; char buffer[256]; /* Watch stdin (fd 0) to see when it has input. */ FD_ZERO(&rfds); FD_SET(0, &rfds); /* Wait up to five seconds. */ tv.tv_sec = 5; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); if (retval) { /* FD_ISSET(0, &rfds) will be true. */ n = read(0,buffer,255); if (n > 0) { buffer[n]='\0'; printf("Data is available: %s\n",buffer); } else printf("error on read\n"); } else printf("No data within five seconds.\n"); exit(0); }