Interview Prep/Linux/Logs, Limits & High-Traffic Tuning

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.

All Linux questions Roadmap: Linux

More on Logs, Limits & High-Traffic Tuning