The read method on the inotify descriptor does not return

一笑奈何 提交于 2019-12-11 04:23:51

问题


My program monitors changes on files using inotify(7)

fd = inotify_init();
inotify_add_watch (fd, "./test.txt", IN_ALL_EVENTS);
//start forever monitor
while(true){
       ssize_t len, i = 0;
       char action[81+FILENAME_MAX] = {0};
       char buff[BUFF_SIZE] = {0};
       len = read (fd, buff, BUFF_SIZE);
       while (i < len) {
           //process event
           i += sizeof(struct inotify_event) + pevent->len;
       }
}

The problem is that the read function only return several times for the firt changes in the monitor file (ACCESS, OPEN, MODIFY events). Unfortunately after that, the read function does not return any more although there a lot of changes in the monitored file.

However, If I reset the inotify descriptor and readd the monitered file agains, ==> the read function always return.

//start forever monitor
while(true){
       ssize_t len, i = 0;
       char action[81+FILENAME_MAX] = {0};
       char buff[BUFF_SIZE] = {0};
       fd = inotify_init();
       inotify_add_watch (fd, "./test.txt", IN_ALL_EVENTS);
       len = read (fd, buff, BUFF_SIZE);
       while (i < len) {
           //process event
           i += sizeof(struct inotify_event) + pevent->len;
       }
}

Could you guys help me explain this error. Thanks so much!!!!!!

来源:https://stackoverflow.com/questions/16397293/the-read-method-on-the-inotify-descriptor-does-not-return

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