A file descriptor (Unix, Linux) or a file handle (Windows) is the connection id from the Operating system to:
For Wikipedia 1), a file descriptor is an index for an entry in a kernel-resident data structure containing the details of all open files.
In POSIX, this data structure is called a file descriptor table, and each process has its own file descriptor table. The user application passes the abstract key to the kernel through a system call, and the kernel will access the file on behalf of the application, based on the key. The application itself cannot read or write the file descriptor table directly.
You can also see a file descriptor as an object that a process uses to open, read or write to a:
A file descriptor is an opaque handle to the underlying machine-specific structure representing:
In Unix-like systems, file descriptors (open files) can refer to:
A file descriptor is a low positive integer.
In Linux, you can set the limit:
There is a limit to the amount of file descriptors per process.
If the file descriptor limit is exceeded for a process, you may see the following errors:
"Too Many Open Files"
"Err#24 EMFILE" (in truss output)
To resolve the issue, raise the OS limit on the number of available file descriptors
In Process explorer,
# for a process
lsof -p PID
# Example for shared library
# lsof -p $PID | awk '{print $9}' | grep .so$
From a terminal shell: self represents the current process
ls -l /proc/self/fd
lrwx------ 1 root root 64 May 31 09:39 0 -> /dev/pts/4
lrwx------ 1 root root 64 May 31 09:39 1 -> /dev/pts/4
lrwx------ 1 root root 64 May 31 09:39 2 -> /dev/pts/4
lr-x------ 1 root root 64 May 31 09:39 3 -> /proc/2924/fd
where:
or from a known PID
ls -l /proc/PID/fd
# from a path
lsof /path
# Monitor continuously
lsof +D /path -r 2
# example : the ``-f -- /'' arguments direct lsof to search for open files with a `/' path name, all open files in the `/' (root) file system.
sudo lsof -f -- /opt/app/logs/servicesFrameworks.log
# example all file in the bin with spy in their name
sudo lsof -s -- /bin/*spy*
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 3802 root cwd DIR 8,3 4096 2 .
lsof 7811 root cwd DIR 8,3 4096 2 .
lsof 7812 root cwd DIR 8,3 4096 2 .
sudo lsof /dev/hd4
Standard stream: Stdout, Stdin, Stderr are file descriptors