【问题标题】:Inotify Delete Events are missing缺少 Inotify 删除事件
【发布时间】: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


    【解决方案1】:

    我解决了。

    inotify_init 为阻塞模式,inotify_init1(IN_NONBLOCK) 使用。

    inotify_init 读取时需要锁

    有用的帖子 http://man7.org/linux/man-pages/man7/inotify.7.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多