1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| #include <fcntl.h>
#include <stdio.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <unistd.h>
int main( int argc, char *argv[])
{
char buf[1024];
struct pollfd pfds[1] = { STDIN, POLLIN}; // No of files discriptors to poll for
int timeout = 5000; // Time Out
int ret = poll(pfds, 1, timeout); // Polling for file discriptors provided with timeout
if ( ret && pfds[0].revents & POLLIN) {
int i = read(0, buf, 1024);
buf[i] = 0;
printf("You Typed : %s\n", buf);
}
else if( ret == 0 ){
printf("Time Out!\n");
}
return 0;
}
|