Using inotify on a busy directory

泄露秘密 提交于 2019-12-13 03:39:22

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!