File System - File Descriptor or Handle (Open File)

Undraw File Manager Re Ms29

About

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.

Management

Limit

Linux

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

Windows

In Process explorer,

Process Explorer Handle Open File Search

Unix

For a process

# for a process
lsof -p PID

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

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

For a device

sudo lsof /dev/hd4

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 - 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 a feature of many operating systems. By default, they: read input from the keyboard and write output to the display. They are the building block of interaction with the user...
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...
Linux - Resource Manager - Processes limitations (/etc/security/limits.conf)

Limiting user processes is important for running a stable system. To limit user process resource, you have just to set shell limit by adding: a user name or group name or all users to /etc/security/limits.conf...



Share this page:
Follow us:
Task Runner