File System - File Descriptor or Handle (Open File)

Undraw File Manager Re Ms29


A file descriptor (Unix, Linux) or a file handle (Windows) is the connection id (generally to a file) from the Operating system in order to perform IO operations (Input/Ouput of Bytes).

For Wikipedia, 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:

A file descriptor is an opaque handle to the underlying machine-specific structure representing:

  • an open file,
  • an open socket,
  • or another source or sink of bytes.

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,

Process Explorer Handle Open File Search


For a process

# for a process
lsof -p PID

# Example for shared library
# lsof -p $PID | awk '{print $9}' | grep .so$

From a terminal/shell

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


or from a known PID

ls -l /proc/PID/fd

From a path

# 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*
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 .

For a device

sudo lsof /dev/hd4

Standard streams (Stdout, Stdin, Stderr)

Standard stream: Stdout, Stdin, Stderr are file descriptors

Documentation / Reference

Discover More
Bash Liste Des Attaques Ovh
Bash - Read (Builtin Command) that capture a line

Read is a bash builtin command and read: by default one line or a number of characters (by option) from: the standard input, or from the file descriptor fd supplied as an argument to the...
Venn Diagram
Collection - Set

A set is: a data structure of the set theory a collection ofdistinct objects (then without duplicate) an unordered collection of objects The objects element of the set have the same type (the type...
Undraw File Manager Re Ms29
File - File

A file is a logical representation of multiple block that can be accessed and manipulated at once by a program. Generally, a file is stored in a durable in the sense that it remains available for programs...
Undraw File Manager Re Ms29
File - Read Operation

read is a file system io operations that opens the file for read access OS In the OS file system, it's equivalent to get a file descriptor. Linux API : read(2) Generally before reading a file,...
Sector Cluster
File - Write

This page is the write operation performed by the OS file system. A write file io operation permits to write data in a file by block of data called cluster (as opposed to a sector for a disk) Before...
Undraw File Manager Re Ms29
File System - ( Symbolic | ln | Soft) link - File Alias - Symlink - Junction - Reparse Points

A soft link, symlink or a symbolic link is a file that redirects (link) to another file. It's the alias functionality of a file system. Unlike a hard link, a symbolic link can link to any file on any...
Undraw File Manager Re Ms29
File System - Open File

When a file is open, it gets a file descriptor (File Handle) from the file system as a mean to manipulate it. Open File from a process are generally: Properties file ...
Undraw File Manager Re Ms29
File System - Watcher

A watcher detect a change of state for a file and emits an event. They are used generally to start a process such as: file synchronization restarting a process and more ...
Card Puncher Data Processing
IO - Standard streams (stdin, stdout, stderr)

Standard Streams are the mechanism by which a process: receive data (stdin) and output data (stdout, stderr). In a shell, by default, they will: read input from the keyboard and write output...
Java Conceptuel Diagram
Java - IO - Byte Stream

Byte I/O Operations (Stream) in java Programs use byte streams to perform input and output of 8-bit bytes. All byte stream classes are descended from this two class: input stream to read byte or...

Share this page:
Follow us:
Task Runner