user1012192
user1012192

Reputation: 21

How does linux kernel know which inotify_handle has a certain watch

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

Answers (1)

user1012192
user1012192

Reputation: 21

My own research, this is the answer:

  1. It is linux kernel; specifically the file system.
  2. When you call 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

Related Questions