Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
File descriptor
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Overview== [[File:File table and inode table.svg|thumb|300px|File descriptors for a single process, file table and [[inode]] table. Note that multiple file descriptors can refer to the same file table entry (e.g., as a result of the [[dup (system call)|dup]] system call{{r|bach}}{{rp|104}}) and that multiple file table entries can in turn refer to the same inode (if it has been opened multiple times; the table is still simplified because it represents inodes by file names, even though an inode can have [[Hard link|multiple names]]). File descriptor 3 does not refer to anything in the file table, signifying that it has been closed.]] In the traditional implementation of Unix, file descriptors index into a per-process '''{{visible anchor|file descriptor table}}''' maintained by the kernel, that in turn indexes into a system-wide table of files opened by all processes, called the '''{{visible anchor|file table}}'''. This table records the ''mode'' with which the file (or other resource) has been opened: for reading, writing, appending, and possibly other modes. It also indexes into a third table called the [[Inode|inode table]] that describes the actual underlying files.<ref name="bach">{{cite book | title=The Design of the UNIX Operating System | first=Maurice J. | last=Bach | year=1986 | edition=8 | publisher=[[Prentice-Hall]] | pages=[https://archive.org/details/designofunixoper00bach/page/92 92β96] | isbn=9780132017992 | url-access=registration | url=https://archive.org/details/designofunixoper00bach/page/92 }}</ref> To perform input or output, 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 does not have direct access to the file or inode tables. On [[Linux]], the set of file descriptors open in a process can be accessed under the path <code>/proc/PID/fd/</code>, where PID is the [[process identifier]]. File descriptor <code>/proc/PID/fd/0</code> is <code>stdin</code>, <code>/proc/PID/fd/1</code> is <code>stdout</code>, and <code>/proc/PID/fd/2</code> is <code>stderr</code>. As a shortcut to these, any running process can also access ''its own'' file descriptors through the folders <code>/proc/self/fd</code> and <code>/dev/fd</code>.<ref>{{Cite web|url=https://unix.stackexchange.com/questions/676683/what-does-the-output-of-ll-proc-self-fd-from-ll-dev-fd-mean|title = Devices - What does the output of 'll /Proc/Self/Fd/' (From 'll /Dev/Fd') mean?}}</ref> 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 [[directory (file systems)|directories]], [[block device|block]] and [[character device]]s (also called "special files"), [[Unix domain socket]]s, and [[named pipe]]s. File descriptors can also refer to other objects that do not normally exist in the file system, such as [[anonymous pipe]]s and [[network socket]]s. The FILE data structure in the [[stdio|C standard I/O library]] usually includes a low level file descriptor for the object in question on Unix-like systems. The overall data structure provides additional abstraction and is instead known as a ''file [[Handle (computing)|handle]].''
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)