← Back to Error Index
root@linuxfix:~/emfile$
EMFILE
Too many open files

Solutions

Prerequisites: Start by updating your system to resolve common issues and ensure the solutions provided below are compatible with your current environment.
check_latest_version && sudo apt update && sudo apt upgrade -y
Check current limits

View file descriptor limits:

ulimit -n
cat /proc/sys/fs/file-max
lsof | wc -l
Increase limits

Raise file descriptor limits:

ulimit -n 4096
echo "* soft nofile 4096" >> /etc/security/limits.conf
echo "* hard nofile 8192" >> /etc/security/limits.conf
Find file leaks

Identify processes with many open files:

lsof -p process_id
ls -la /proc/process_id/fd/
netstat -an | grep ESTABLISHED | wc -l

What is EMFILE?

EMFILE occurs when a process has reached its limit for open file descriptors.

Common scenarios: Applications opening many files without closing them, file descriptor leaks, or insufficient file descriptor limits.

Common Causes

  • File descriptor leaks in applications
  • Too many files opened simultaneously
  • Low file descriptor limits
  • Network connections counting as files
  • Pipes and sockets not closed

Debugging Tips

cat /proc/sys/fs/file-nr
lsof | awk '{print $2}' | sort | uniq -c | sort -nr
ps aux | grep process_name
cat /proc/process_id/limits

Prevention

  • Always close opened files
  • Monitor file descriptor usage
  • Set appropriate limits
  • Fix resource leaks in applications
errno files limits resources