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