01 · Why it’s true
Unix exposes files, network sockets, pipes, and devices through one interface: a small integer called a file descriptor, an index into the process’s table of open resources. By convention 0, 1, and 2 are standard input, output, and error.
Every open file or connection holds a descriptor until it’s closed, and each process has a limit (see ulimit -n). A program that leaks descriptors, or a server holding many connections, eventually fails with “too many open files” — even with plenty of CPU and memory to spare.
02 · Picture it
03 · In the interview
- Diagnosing “too many open files”.
- Inspecting open descriptors with
ls /proc/<pid>/fdorlsof -p <pid>. - Sizing limits for servers that hold many connections.
04 · Practice question
“A service starts failing with “too many open files” after a few days of uptime. What do you do?”
A strong answer covers
- Count descriptors over time (
ls /proc/<pid>/fd | wc -l); steady growth means a leak. - Use
lsof -p <pid>to see what they are — lots of sockets to one host, files, pipes. - Common causes: connections or files not closed on error paths, or HTTP response bodies never closed.
- Short term: raise the limit or restart. Long term: fix the leak and alert on descriptor usage.