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.
More on Processes, memory and OOM
A Java service disappears without an error in its own log. `dmesg` shows `Out of memory: Killed process 4121 (java) total-vm:... anon-rss:...`.BeginnerA service gets killed with `Memory cgroup out of memory: Killed process ...` but the host has 20 GB free.Intermediate`ps` shows dozens of processes in state `Z` with `<defunct>`.BeginnerZombie count keeps climbing into the thousands and new processes fail with `fork: Resource temporarily unavailable`.AdvancedYou raised `nofile` in `/etc/security/limits.conf` to 65536, but the service still shows `Max open files 1024`.IntermediateThe whole host can't open files: `VFS: file-max limit 98304 reached` in `dmesg`.Advanced