Skip to content

Instantly share code, notes, and snippets.

@20k-ultra
Last active October 3, 2025 06:14
Show Gist options
  • Save 20k-ultra/2d548507d425bb54d08e413a654f46c3 to your computer and use it in GitHub Desktop.
Save 20k-ultra/2d548507d425bb54d08e413a654f46c3 to your computer and use it in GitHub Desktop.
check inotify usage
#!/bin/bash
total_watches=0
total_instances=0
for pid in $(ls /proc | grep -E "^[0-9]+$"); do
for fd in $(ls /proc/$pid/fd 2>/dev/null); do
link=$(readlink /proc/$pid/fd/$fd 2>/dev/null)
if [[ "$link" == "anon_inode:inotify" ]]; then
total_instances=$((total_instances + 1))
# Count lines starting with "inotify" in fdinfo
count=$(grep "^inotify" /proc/$pid/fdinfo/$fd 2>/dev/null | wc -l)
total_watches=$((total_watches + count))
fi
done
done
limit=$(cat /proc/sys/fs/inotify/max_user_watches)
percent=$(echo "scale=4; $total_watches * 100 / $limit" | bc)
echo "Total watches: $total_watches"
echo "Watch limit: $limit"
echo "Usage percent: $percent%"
echo "Total instances: $total_instances"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment