inotify描述符上的read方法不返回

时间:2013-05-06 10:58:24

标签: c++ c file-descriptor inotify file-monitoring

我的程序使用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,OPEN,MODIFY事件)中的更改,read函数只返回几次。不幸的是,尽管受监视文件中有很多变化,但read函数不再返回。

但是,如果我重置inotify描述符并再次读取monitered文件,==&gt; read函数总是返回。

//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;
       }
}
你能帮我解释一下这个错误。非常感谢!!!!!!

0 个答案:

没有答案