【发布时间】:2018-07-10 00:44:53
【问题描述】:
在同一目录中删除文件时缺少事件。
inotify 监控目录:./test 删除命令:rm -rf ./test/*
文件数:20;
但是 event notify 12,这是怎么回事?
int fileDescripter = inotify_init();
char buffer[BUF_LEN];
int watchDescripter = inotify_add_watch(fileDescripter, path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE);
while(true)
{
read(fileDescripter, buffer, BUF_LEN);
struct inotify_event *evt_inotify = (struct inotify_event*) &buffer;
string filename(evt_inotify->name);
cout << " CATCH : " << path+"/"+filename << endl;
if(evt_inotify->len){
if(evt_inotify->mask & IN_CREATE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR CREATE" << endl;
}
else
{
cout << "FILE CREATE" << endl;
}
}
else if(evt_inotify->mask & IN_DELETE)
{
if(evt_inotify->mask & IN_ISDIR)
{
cout << "DIR DELETE" << endl;
}
else
{
cout << "FILE DELETE" << endl;
}
}
else if(evt_inotify->mask & IN_MODIFY)
{
if(evt_inotify->mask & IN_ISDIR)
{
}
else
{
}
}
}
}\
第12行,打印的是event notify count(12)
【问题讨论】:
标签: c++ linux file monitoring inotify