Reputation: 21
I understood that linux kernel provides "inotify mechanism" to monitor file system.
According to inotify, inotify_init()
returns fd to receive inotify_event
from kernel.
(I understood kernel will write inotify_event
on it.)
1) And if I add new watch with the inotify fd
using inotify_add_watch()
, Who will write inotify_event
on inotify fd when the watched file has got an event.
2) (if kernel does,) when kernel detects an event for watched file, how does kernel decide which inotify fd(inotify_instance)
has to update with this inotify_event
?
Upvotes: 0
Views: 375
Reputation: 21
My own research, this is the answer:
inotify_add_watch()
to certain file, inotify
stores some information of inotify
watch into that file's inode
structure.Then, whenever file system deals with that file, it checks the file's inode
sturture - whether there exists inotify watches
or not. If inotify
watches found from inode
structure, inotify
reports inotify_event
.
Upvotes: 2