在文件 /usr/include/sys/inotify.h. 中,您可以找到事件结构的定义,它是一种 C 结构,如清单 2 所示.
清单 2. 事件结构的定义
struct inotify_event
{
int wd; /* The watch descriptor */
uint32_t mask; /* Watch mask */
uint32_t cookie; /* A cookie to tie two events together */
uint32_t len; /* The length of the filename found in the name field */
char name __flexarr; /* The name of the file, padding to the end with NULs */
}
% cd $HOME
% touch a b c
The file a was created.
The file b was created.
The file c was created.
% ./watcher &
% rm a b c
The file a was deleted.
The file b was deleted.
The file c was deleted.
% ./watcher &
% touch a b c
The file a was created.
The file b was created.
The file c was created.
% ./watcher &
% cat /etc/passwd >> a
The file a was modified.
% ./watcher &
% mkdir d
The directory d was created.