I am trying to write a program which checks whether a file is modified or not. if it is modified it must exit. I have written the following code. but the program is not exiting even though i modified the file. i am using f_notify of fcntl to receive notfification.
#define _GNU_SOURCE
#include<unistd.h>
#include<fcntl.h>
#include <stdio.h>
#include <signal.h>
main()
{
int fd;
int sig_hand();
signal(SIGIO,sig_hand);
fd = open("/root/br.xml", O_RDONLY);
fcntl(fd,F_SETOWN,getpid());
fcntl(fd,F_SETFL,FASYNC);
fcntl(fd, F_NOTIFY, DN_MODIFY);
for(;
{
printf("Here i am waiting for the file to be changed\n");
}
}
int sig_hand()
{
printf("File is changed, i m exiting ");
exit(0);
}
any help plz
rajesh