Linux EMFILE/ENFILE (errno 24/23) — Too Many Open Files
Errorerrno
Overview
Linux EMFILE and ENFILE errors occur when a process or the entire system has reached its maximum limit of open file descriptors.
Key Details
- EMFILE (errno 24): per-process file descriptor limit reached (ulimit -n, default 1024)
- ENFILE (errno 23): system-wide file descriptor limit reached (fs.file-max)
- File descriptors include files, sockets, pipes, and device handles
- Network servers can exhaust file descriptors with many concurrent connections
- Docker containers inherit ulimits from the host or can set their own
Common Causes
- Application not closing file descriptors (file descriptor leak)
- Too many concurrent network connections (each socket is a file descriptor)
- Per-process limit (ulimit -n) set too low for the application's needs
- System-wide limit (fs.file-max) too low for high-connection servers
- File descriptor leak in long-running daemons accumulating over time
Steps
- 1Check current limits: ulimit -n (per-process) and cat /proc/sys/fs/file-max (system-wide)
- 2Check current usage: ls /proc/PID/fd | wc -l to count open FDs for a specific process
- 3Increase per-process limit: ulimit -n 65536 or edit /etc/security/limits.conf
- 4Increase system limit: echo 'fs.file-max = 1000000' >> /etc/sysctl.conf && sysctl -p
- 5For systemd services: add LimitNOFILE=65536 in the service unit file
Tags
linuxemfileenfilefile-descriptorsulimit
More in Errno
linux-errno-1-epermLinux errno 1 (EPERM) — Operation Not Permitted
Warninglinux-errno-2-enoentLinux errno 2 (ENOENT) — No Such File or Directory
Warninglinux-errno-5-eioLinux errno 5 (EIO) — Input/Output Error
Errorlinux-errno-11-eagainLinux errno 11 (EAGAIN) — Resource Temporarily Unavailable
Informationallinux-errno-12-enomemLinux errno 12 (ENOMEM) — Out of Memory
Criticallinux-errno-13-eaccesLinux errno 13 (EACCES) — Permission Denied
WarningFrequently Asked Questions
Track FD count over time: watch 'ls /proc/PID/fd | wc -l'. If it increases continuously, the process has a leak. Use lsof -p PID to see what is open.