Monitoring file using inotify

后端 未结 2 2038
-上瘾入骨i
-上瘾入骨i 2021-02-06 11:33

I am using inotify to monitor a local file, for example \"/root/temp\" using

inotify_add_watch(fd, \"/root/temp\", mask).

When this file is de

2条回答
  •  鱼传尺愫
    2021-02-06 12:10

    In order to see a new file created, you need to watch the directory, not the file. Watching a file should see when it is deleted (IN_DELETE_SELF) but may not spot if a new file is created with the same name.

    You should probably watch the directory for IN_CREATE | IN_MOVED_TO to see newly created files (or files moved in from another place).

    Some editors and other tools (e.g. rsync) may create a file under a different name, then rename it.

提交回复
热议问题