What Does File Descriptor Mean?
For most operating systems, a file descriptor (FD) is a small non-negative integer that helps in identifying an open file within a process while using input/output resources like network sockets or pipes. In a way, it can be considered as an index table of open files. When there are read, write or closing file operations, one of the input parameters considered is the file descriptor. File descriptors form an important component of POSIX application programming interface and provide a primitive, low-level interface to input or output operations.
Techopedia Explains File Descriptor
A kernel creates a file descriptor whenever it encounters an open call. In many ways, the gateway into the kernel’s abstractions of underlying hardware can be considered as file descriptors. In the Unix operating system, the standard input is represented by file descriptor 0, the standard output is represented by file descriptor 1 and standard error file is represented by file descriptor 2. In other words, corresponding to the three standard streams, each UNIX process would have three standard file descriptors. Both streams and file descriptors can represent a device connection, however for controlling specific devices, file descriptors need to be used. In most operating systems such as UNIX, file descriptors are represented as objects of type “int.” The file descriptor is used by the kernel as an index in the file description table in order to determine which process originally opened a specific file and then allow performing the requested operations on the opened device or file.
From an application programming perspective, file descriptors need to be used if there are any input or output operations in special modes, including non-blocking inputs. Unlike streams which provide high functions for controlling, a file descriptor interface provides only simple functions for the transfer of character blocks. Low-level operations can be performed directly on the file descriptor.