报 Too many open files,定位是哪个进程漏了句柄

先确认上限:ulimit -n 只是当前 shell 的限制,进程真正的上限要看 /proc/<pid>/limits 里的 Max open files;systemd 托管的服务要去改 LimitNOFILE,改 limits.conf 对它无效。再统计各进程已打开的句柄数,排第一的通常就是元凶。接着看它开的是什么,若全是同一地址的 socket,多半是连接没关闭或没归还连接池。

ulimit -n
cat /proc/<pid>/limits | grep 'Max open files'
for p in /proc/[0-9]*; do echo "$(ls $p/fd 2>/dev/null | wc -l) $(cat $p/comm 2>/dev/null)"; done | sort -rn | head
ls -l /proc/<pid>/fd | awk '{print $NF}' | sort | uniq -c | sort -rn | head
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容