#include <stdio.h>
#include <stdlib.h>
#include <sys/poll.h>
#include <unistd.h>
main()
{
struct pollfd fds;
char data[80]; /* Record read from the file. */
int retval;
int n;
fds.fd = STDIN_FILENO;
fds.events = POLLIN;
fds.revents = 0;
while ((retval=poll(&fds,1,5000))!=-1) // 5000 milliseconds
{
printf("retval: %d revents: %d\n",retval,fds.revents);
if(fds.revents==1){
printf("reading data!\n");
n=read(STDIN_FILENO, data, 100); /* Read next record */
data[n]=0;
printf("%s",data); /* O/P the record to the screen */
}
if (data[0] == '#') exit; /* filter out the comments */
}
} |