Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

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))

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.