File Descriptor

In computer programming, a file descriptor (FD) is an abstract indicator for accessing a file. The term is generally used in POSIX operating systems. In Microsoft Windows terminology and in the context of the C standard I/O library, file handle is preferred, though the latter case is technically a different object (see below).

In POSIX, a file descriptor is an integer, specifically of the C type int. There are three standard POSIX file descriptors, corresponding to the three standard streams, which presumably every process (save perhaps a daemon) should expect to have:

Integer value Name
0 Standard input (stdin)
1 Standard output (stdout)
2 Standard error (stderr)

Generally, a file descriptor is an index for an entry in a kernel-resident array data structure containing the details of open files. In POSIX this data structure is called a file descriptor table, and each process has its own file descriptor table. The process passes the file descriptor to the kernel through a system call, and the kernel will access the file on behalf of the process. The process itself cannot read or write the file descriptor table directly.

On Linux, the set of file descriptors open in a process can be accessed under the path /proc/PID/fd/, where PID is the process identifier.

In Unix-like systems, file descriptors can refer to any Unix file type named in a file system. As well as regular files, this includes directories, block and character devices (also called "special files"), Unix domain sockets, and named pipes. File descriptors can also refer to other objects that do not normally exist in the file system, such as anonymous pipes and network sockets.

The FILE data structure in the C standard I/O library usually includes a low level file descriptor for the object in question on Unix-like systems. Since file handle refers to this additional layer, it is not interchangeable with file descriptor.

Microsoft Windows also uses the term file handle to refer to the more low-level construct, akin to POSIX's file descriptors. Microsoft's C libraries also provide compatibility functions which "wrap" these native handles to support the POSIX-like convention of integer file descriptors as detailed above.

Read more about File Descriptor:  Operations On File Descriptors, Upcoming Operations, File Descriptors As Capabilities

Other articles related to "file descriptor, file, file descriptors":

Asynchronous I/O - Forms - Select(/poll) Loops
... a select loop uses the select system call to sleep until a condition occurs on a file descriptor (e.g ... parameters of the select call, the loop finds out which file descriptor has changed and executes the appropriate code ... it depends heavily on the Unix paradigm that "everything is a file" any blocking I/O that does not involve a file descriptor will block the process ...
DNET - Netman
... allowing them to support up to 4095 client connections through one file descriptor (to netman) ... Simple resident and transient servers consumed a file descriptor per client connection ... mount points, at a minimum.) The /usr/lib/net/servtab file was the usual location for the configuration file controlling WAN configuration and transient servers ...
File Descriptors As Capabilities
... Unix file descriptors behave in many ways as capabilities ... that what is actually passed is a reference to an "open file description" that has mutable state (the file offset, and the file status and access flags) ... This complicates the secure use of file descriptors as capabilities, since when programs share access to the same open file description, they can interfere with each other's ...
... a0 = full path (zero terminated string with no line feed), $a1 = flags, $a2 = UNIX octal file mode (0644 for rw-r--r--) $v0 = file descriptor file_read $v0 = 14 $a0 ...
Doors (computing) - Overview
... A server can "attach" a door to a file, enabling clients to connect to that door simply by opening that file ... The ls -l command will then show the file with a 'type' of "D" (not to be confused with "d" for a directory) — for example Clients use door_call to invoke the door's server procedure, passing a ... the same way as the ioctl system call.) Every file descriptor is accompanied by a flags word ...

Famous quotes containing the word file:

    Probably nothing in the experience of the rank and file of workers causes more bitterness and envy than the realization which comes sooner or later to many of them that they are “stuck” and can go no further.
    Mary Barnett Gilson (1877–?)