2

After creating a file descriptor by calling inotify_init() I add thousands of watches to the inotify instance(hope it is right to call that so).

My questions is if my program crashes what happens to those watch descriptors? Can I clear them all after the crash? It is important since allowed watch descriptor count is limited by /proc/sys/fs/inotify/max_user_watches

destan
  • 1,157

1 Answers1

3

File descriptors, whether they point to files, sockets, or inotify instances, must belong to at least one process – they are automatically closed when the last process exits.

Similarly, when all file descriptors referring to an inotify instance have been closed, the underlying object and its resources are freed for reuse by the kernel; all associated watches are automatically freed. (inotify(7))

grawity
  • 501,077