TOPIC LINUX
File Descriptors why 'too many open files' happens
IN 10 SECONDS
In Linux, everything is a file. The kernel indexes open files, directories, network sockets, and pipes using integer handles called File Descriptors (FDs). Each process has a maximum limit of open FDs.
GOTCHA Forgetting to close database clients, HTTP connections, or files in your application code leaks FDs, causing services to crash once limits are reached.
HOW A FILE DESCRIPTOR IS HANDLED
01 Open system call application opens a log file or accepts a network socket connection.
02 Allocation kernel allocates a free file descriptor integer (e.g. 3) to the process.
03 I/O process reads/writes data referencing this integer handle.
04 Limits check if the process exceeds maximum ulimit boundaries, it throws a 'Too many open files' exception.
POKE IT YOURSELF
ulimit -n — check the maximum open file descriptor limit for your process
lsof -p PID | wc -l — count open file descriptors for a specific process
Drill this topic →
~70 sec read