Interview Prep/Linux/Processes, memory and OOM

An app crashes under load with `java.io.IOException: Too many open files` (or `EMFILE`).

BeginnerTroubleshootingProcesses, memory and OOM
Answer

Likely causes → The process hit its open-file limit (RLIMIT_NOFILE), often 1024 by default, or it's leaking file descriptors/sockets.

Diagnose →

cat /proc/<PID>/limits | grep 'open files'
ls /proc/<PID>/fd | wc -l
sudo lsof -p <PID> | awk '{print $5}' | sort | uniq -c | sort -rn | head

Fix → For a systemd service, set LimitNOFILE=65536 in a drop-in, daemon-reload and restart. If the count grows forever, fix the leak (unclosed sockets/files).

Prevent → Monitor fd count vs limit per process.

All Linux questions Roadmap: Linux

More on Processes, memory and OOM