问题
I am using inotify
on a busy directory(files keep on getting generated). I wish to catch the IN_CLOSE_WRITE
events for all of them.
So I tried something like this.
fd = inotify_init();
inotify_add_watch(fd, DIR_PATH, IN_CLOSE_WRITE);
while(1) {
len = read(fd, buff, INOTIFY_EVENT_SIZE);
if (len < 0) {
PRINT_ERROR("Read failed. Keep watching.\n");
continue;
}
/* Process the event */
}
This method is failing to catch the events that are generated while I am processing the event of first read. I expected it to work though.
How should I handle this? Please let me know in case you see something missing.
回答1:
I was waiting on IN_CLOSE_WRITE, But the files in my dir were actually moved from a diff place. SO the event was not getting caught. I changed the event mast to IN_MOVE and it worked well.
来源:https://stackoverflow.com/questions/24816535/using-inotify-on-a-busy-directory