LINUX / A CONCEPT NOTE
File Descriptors
why 'too many open files' happens
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
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.
02 / FOLLOW THE MECHANISM
How a file descriptor is handled
Open system call
application opens a log file or accepts a network socket connection.
Allocation
kernel allocates a free file descriptor integer (e.g. 3) to the process.
I/O
process reads/writes data referencing this integer handle.
Limits check
if the process exceeds maximum ulimit boundaries, it throws a 'Too many open files' exception.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
check the maximum open file descriptor limit for your process
ulimit -ncount open file descriptors for a specific process
lsof -p PID | wc -l05 / CHECK YOURSELF
Could you explain File Descriptors to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.
Up next in Linux & systemsSymlinks & Hard Linkstwo names for one file