Question: My server hits "too many open files" errors. Which process is the culprit?
Try: sudo lsof | awk '{print $2}' | sort | uniq -c | sort -rn | head -10
Info: lsof lists open file descriptors across processes. Grouping the output by PID counts open handles and helps identify processes consuming large numbers of file descriptors before they reach their limits in /proc/PID/limits.
Examples:
- $
sudo ls /proc/*/fd 2>/dev/null | wc -l# Count system-wide open file descriptors - $
sudo lsof -p 2456 | wc -l# Count open files for a specific PID - $
sudo prlimit --pid 2456 --nofile=65536:65536# Dynamically raise a process file limit
Note: Check the current process limits with cat /proc/PID/limits. You can dynamically adjust limits with prlimit or configure persistent limits through /etc/security/limits.conf. High-concurrency servers may require significantly higher file descriptor limits than the traditional 1024 soft limit.
Leave a Reply