file descriptor

A small number the operating system gives a process for each open file, socket or pipe, used in every later read or write.

In more detail

Descriptors 0, 1 and 2 are standard input, standard output and standard error, and every process starts with them already open. Shell redirections work on these numbers: 2> redirects descriptor 2, and 2>&1 makes it point wherever descriptor 1 points. A process may only have a limited number open at once, so descriptors that are never closed eventually cause errors.

Examples

Dead WebSocket connections that are never closed leak file descriptors.
Go: defer f.Close() after os.Open
Every process starts with descriptors 0, 1 and 2 for standard input, output and error. An open descriptor keeps its file alive: a deleted file's data is not freed until every descriptor to it is closed. Counting a process's open descriptors, for example under /proc/PID/fd, is part of inspecting its resources.
In Node.js a FileHandle wraps one, and every socket uses one too.

Related terms

Taught in

References

Certification courses