I use inotifywait for event trigger which put file.

When many files are watched by inotifywait, when max_user_watches is exceeded, the following error occurs.

Terminating since out of inotify watches.#012Consider increasing /proc/sys/fs/inotify/max_user_watches

It is necessary to tune /proc/sys/fs/inotify/max_user_watches, but is it possible to check the current file watch number?

Is there a way to check like file-nr in file descriptor?


I wish I was able to answer with something smarter, but the only way I found to count the inotify(7) watches set by a user is this:

find /proc/*/fd -user "$USER" -lname anon_inode:inotify \
   -printf '%hinfo/%f\n' 2>/dev/null |
   xargs cat | grep -c '^inotify'

Change "$USER" with the actual user you want info about; "`id -u`" for the current user. Notice that the max_user_watches is a per-user limit, not per process, or per inotify instance / file descriptor.

This will first find all open file descriptors created by inotify_init*(2), and will then look into the corresponding /proc/PID/fdinfo/FD file for the info about the watch descriptors added with inotify_add_watch(2) to each of them (look into the proc(5) manpage under /proc/[pid]/fdinfo/ for a description of the inotify-specific entries). The -c option of grep will let it print a count of all lines that match a pattern.

Note: the counter for inotify_watches is kept just like other per-user counters in a struct ucounts referenced from the user namespace structure -- see include/linux/user_namespace.h; but I wasn't able to find any interface exposing those counters to userland.


I cobbled together this little script based on @mosvy's answer.

$ inotify-consumers 

    COUNT     PID     CMD
    7111     3079  node /home/carlerik/dev/nimble-frontend/node_modules/.bin/webpack --config config/webpack.dev.js
      79     1541  /usr/lib/gnome-settings-daemon/gsd-xsettings
      30     1664  /usr/lib/gvfs/gvfsd-trash --spawner :1.22 /org/gtk/gvfs/exec_spaw/0
      14     1630  /usr/bin/gnome-software --gapplication-service
      14     1191  /lib/systemd/systemd --user
      10     1371  /usr/bin/gnome-shell
       9     2459  update-notifier
       7     1635  nautilus-desktop
       5     1191  /lib/systemd/systemd --user
       2     1536  /usr/lib/gnome-settings-daemon/gsd-sound
       2     1452  /usr/lib/evolution/evolution-source-registry
       2     1429  ibus-daemon --xim --panel disable
       2     1248  /usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
       1     1863  /usr/lib/gnome-terminal/gnome-terminal-server
       1     1713  /usr/lib/evolution/evolution-addressbook-factory
       1     1678  /usr/lib/ibus/ibus-engine-simple
       1     1625  /usr/lib/evolution/evolution-calendar-factory
       1     1560  /usr/lib/gnome-settings-daemon/gsd-housekeeping
       1     1556  /usr/lib/gnome-settings-daemon/gsd-color
       1     1499  /usr/lib/gvfs/gvfs-afc-volume-monitor
       1     1487  /usr/lib/gnome-online-accounts/goa-identity-service
       1     1480  /usr/lib/gvfs/gvfs-udisks2-volume-monitor
       1     1460  /usr/lib/gnome-online-accounts/goa-daemon
       1     1440  /usr/lib/ibus/ibus-portal
       1     1435  /usr/lib/ibus/ibus-x11 --kill-daemon
       1     1433  /usr/lib/ibus/ibus-dconf
       1     1410  /usr/bin/pulseaudio --start --log-target=syslog
       1     1410  /usr/bin/pulseaudio --start --log-target=syslog
       1     1410  /usr/bin/pulseaudio --start --log-target=syslog
       1     1371  /usr/bin/gnome-shell
       1     1352  /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --print-address 3
       1     1254  /usr/lib/gnome-session/gnome-session-binary --session=ubuntu
       1     1254  /usr/lib/gnome-session/gnome-session-binary --session=ubuntu
       1    12287  /home/carlerik/.sdkman/candidates/java/current/bin/java -classpath /usr/share/maven/boot/plexus-classworlds-2.x.jar -Dcl
       1     1191  /lib/systemd/systemd --user

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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