在 Debian 上调试 inotify(文件系统事件监控)通常分几个层面:内核/系统限制、用户态工具、应用层日志、以及代码级调试。下面按实用程度给你一套方法。
cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances
cat /proc/sys/fs/inotify/max_queued_events
常见问题:
max_user_watches 太小(默认通常 8192)临时调整:
sudo sysctl fs.inotify.max_user_watches=524288
永久生效:
echo 'fs.inotify.max_user_watches=524288' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
inotifywait(inotify-tools)sudo apt install inotify-tools
监听目录:
inotifywait -mr /path/to/dir
常用参数:
-m 持续监控-r 递归-e create,modify,delete,attrib--format '%w %e %f'示例:
inotifywait -m -r -e modify,create,delete /var/www
✅ 这是最直接的“看到 inotify 有没有收到事件”的方法。
容器内 inotify 限制是宿主机上的
docker run --rm -it debian sh
cat /proc/sys/fs/inotify/max_user_watches
解决方法:
DEBUG=chokidar nodemon app.js
或:
node --trace-warnings app.js
pip install watchdog
watchmedo log \
--generator-command='echo %(message)s' \
/path
sudo lsof | grep inotify
或:
find /proc/*/fd -type l 2>/dev/null | xargs ls -l 2>/dev/null | grep inotify
strace -e inotify_init,inotify_add_watch,inotify_rm_watch -f -p <PID>
或启动程序时:
strace -f -e trace=inotify inotifywait /tmp
❌ inotify 不递归子目录(需要程序自己处理)
❌ 编辑器“保存”是 rename + create(不是 modify)
❌ NFS / FUSE / 网络盘不支持 inotify
❌ 挂载点变化时 watcher 失效
你可以告诉我:
我可以直接给你对应的调试命令或修复方案。