What is a file descriptor and why everything in Linux is a file
Published on 2026-09-12 by frfrand
What is a file descriptor, why in Linux everything is handled as a file, how programs are chained, and what "too many open files" means.

Short answer: a file descriptor is the integer that the kernel gives to a process for each thing it opens: a file, a socket, a pipe, or a device. Since everything is read and written with the same calls, programs can be chained without knowing what is on the other side. "Too many open files" means the process reached its descriptor limit, not that the disk is full.
"In Unix everything is a file" is a phrase that is repeated a lot and explained little. The file descriptor is where that idea becomes concrete.
A number, nothing more
When a process opens something, the kernel returns an integer to it: the descriptor. From there, the process uses that number to read, write, and close.
What is interesting is what can be behind that number: a file on disk, a network connection, a pipe to another process, a device, the keyboard, a timer.
The interface is the same for all. Reading from a file and reading from a socket use the same system call.
The first three are reserved by convention:
0 standard input 1 standard output 2 standard error
And those you open afterward receive the lowest free number: 3, 4, 5.
Why that abstraction is so powerful
Because it allows programs to be combined without knowing anything about each other.
When you write something like this:
$ cat registro.txt | grep error > salida.txt
What happens is that the shell manipulates descriptors: it connects the output of one to the input of the other via a pipe, and redirects the final output to a file.
Neither cat nor grep know anything about this. Each one reads from its descriptor 0 and writes to its descriptor 1, without knowing what is on the other side. That is, in essence, the reason why the Unix command line is composable.
And it explains something that confuses many people: why errors do not go through the pipe. Since they go to descriptor 2 and the pipe connects descriptor 1, error messages keep appearing on screen. That is deliberate: it allows you to see errors even when you are redirecting the output.
Too many open files
The error that made the concept famous.
Each process has a limit of open descriptors. The default soft limit is usually 1024, which for a server with many connections quickly becomes insufficient.
View the current limit:
ulimit -n
View how many a specific process has open:
ls /proc/<pid>/fd | wc -l
And view what it has open, which is what really helps:
ls -l /proc/<pid>/fd
This shows each descriptor and what it points to. It is the fastest way to detect a leak: if you see hundreds of descriptors pointing to the same file or to closed sockets, there is code that opens and does not close.
Raising the limit, and the detail that is forgotten
It can be raised in /etc/security/limits.conf, but there is a very common trap: this does not apply to systemd services.
Services need their own adjustment:
[Service] LimitNOFILE=65535
It is the number one cause of "I raised the limit and it keeps failing".
A detail that surprises
If you delete a file that a process has open, the space is not freed until that process closes it. The name disappears from the directory, but the content remains alive because there is a descriptor pointing to it.
This is the explanation of the classic mystery: you deleted a giant log, "df" still shows the disk full, and "du" finds nothing large. The file exists without a name, sustained by a descriptor.
lsof +L1
lists exactly those cases. The solution is to restart the process that has it open, or ask it to reopen its logs.
Example: a service runs out of file descriptors
If a server opens too many connections or files simultaneously, it may encounter the error «Too many open files». This does not mean the disk is full: the process or system reached a descriptor limit. Investigate sockets, open files, and possible leaks before modifying limits.
In an application hosted on an ArduMaker VPS, lsof -p PID helps observe what a process keeps open, while systemd limits can be reviewed in the service configuration. Increasing limits without understanding the cause can only delay the failure.
Related: What is a Linux process · What is a worker.
Frequently asked questions
What are descriptors 0, 1 and 2? Standard input, standard output and standard error. That's why 2> redirects only errors and a pipe (|) does not include them.
How do I increase the open file limit of a service? With LimitNOFILE= in the [Service] section of its systemd unit. /etc/security/limits.conf only affects user sessions, not services.
Why does df say the disk is full if I deleted the file? Because a process still has it open. lsof +L1 lists deleted files that are still open; space is freed by restarting that process or making it reopen its files.