Join Nostr
2026-01-27 15:28:54 UTC
in reply to

Ammar Nofan Faizi on Nostr: > the number of fds will double due to inotify Haaah? That is not true. One inotify ...

> the number of fds will double due to inotify

Haaah?

That is not true.

One inotify fd can monitor many files. You only need one extra fd.
```
fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
wd1 = inotify_add_watch(fd, "/path/to/file1", IN_MODIFY | IN_DELETE_SELF);
wd2 = inotify_add_watch(fd, "/path/to/file2", IN_MODIFY | IN_DELETE_SELF);
...
wdN = inotify_add_watch(fd, "/path/to/fileN", IN_MODIFY | IN_DELETE_SELF);
```
Note: wd is not a file descriptor. It is just a watch descriptor (an integer) returned by inotify_add_watch().

Unlike a file descriptor, a watch descriptor is not affected by `RLIMIT_NOFILE`.

The limit of wd is configured separately by `/proc/sys/fs/inotify/max_user_watches`.

Then, to remove a watch:
```
inotify_rm_watch(fd, wdX);
```
So you only need to manage one inotify fd, no matter how many files you monitor.