-->

在inotify的描述符的读法不返回(The read method on the inotify

2019-10-18 03:02发布

我的程序中使用监控上的文件变化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;
       }
}

问题是,阅读功能仅适用于监视器文件(ACCESS,打开,修改事件)的firt变化返回几次。 不幸的是在那之后,读函数不返回任何更多的虽然有很多的监控文件的变化。

不过,如果我重新设置的inotify描述符和重新进行添加的monitered文件agains,==>读功能总是返回。

//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;
       }
}

难道你们帮我解释一下这个错误。 非常感谢!!!!!!

文章来源: The read method on the inotify descriptor does not return