我以前从未使用过C。此脚本将侦听器添加到目录中,并通过回显到终端来通知用户,然后在文件事件发生时退出。我想将脚本修改为不退出,而是继续监视文件夹。我认为关键可能是这一行:
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.
但我不属于这一类。