How do you find which process is leaking file descriptors?
IntermediateProductionLogs, Limits & High-Traffic Tuning
Answer
for p in /proc/[0-9]*; do echo "$(ls $p/fd 2>/dev/null | wc -l) $(cat $p/comm 2>/dev/null) ${p#/proc/}"; done | sort -rn | head
sudo lsof -p <pid> | awk '{print $5}' | sort | uniq -c | sort -rn # by type
sudo ls -l /proc/<pid>/fd | grep -c socket
A count that grows forever, especially sockets in CLOSE_WAIT, means the app is not closing connections. Raising the limit only buys time.
More on Logs, Limits & High-Traffic Tuning
How does log management work on a modern Linux server?BeginnerWhy centralize logs instead of reading them on each server?BeginnerWrite a logrotate config for an application log.BeginnerWhat is the difference between `copytruncate` and `create` + postrotate signal?IntermediateLogs rotated but disk usage did not drop. Why?IntermediateHow often does logrotate run, and why does `maxsize` sometimes not trigger in time?Intermediate