帮助inotify C脚本

资源

我以前从来没有用过C 此脚本将侦听器添加到目录中,并通过回显到terminal来通知用户,然后在发生文件事件时退出。 我想修改脚本不退出,而是继续监视文件夹。 我认为关键可能是这一行:

length = read( fd, buffer, BUF_LEN );

但我真的不明白这里发生了什么。 read()函数的描述可能对那些熟知C的人有帮助:

Using inotify is simple: Create a file descriptor, attach one or more watches (a watch is a path and set of events), and use the read() method to receive event information from the descriptor. Rather than burn scarce cycles, read() blocks until events occur.

但我不属于这个类别。

程序存在只是因为没有任何东西阻止它exit( 0 ); 一旦发现事件。 你可以包装一切从fd = inotify_init(); to ( void ) close( fd ); 在一个循环中,只要你想要它就会重新开始。

问题不在length = read( fd, buffer, BUF_LEN ); 。 这部分只是等待事件发生,并不要求程序退出。 main被设计成在一个运行和退出中执行。