I want to return from select() whenever file was modified.
I wrote following way but select is returning continuously even tough file was not modified.
Please help me to solve this problem
Code:
#include <sys/time.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <sys/select.h>
int main(){
char filepath[1024];
memset(filepath,0,1024);
strcpy(filepath,"/home/test/abc.log");
int fd;
fd_set select_list;
FD_ZERO(&select_list);
fd = open (filepath,O_RDONLY);
if ( fd > 0 ) {
if ( FD_ISSET( fd, &select_list ))
FD_CLR( fd, &select_list );
FD_SET( fd, &select_list );
printf("Added %s File for Stream watch,%d\n", filepath,fd);
}
else {
printf("Failed to add the file %s to stream list,Error:%s\n",filepath,strerror(errno));
}
while(1)
{
printf("==============1\n");
int bReady = select( fd+1, &select_list, NULL, NULL, NULL );
printf("==============2:%d\n",bReady);
if(bReady <= 0)
{
continue;
sleep(15);
}
printf("==========3:%d\n",bReady);
sleep(2);
}
}
ThanQ,
Nagendra