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.OpenEvery 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
- standard output and standard error — The two channels a program writes normal output (stdout) and error messages (stderr) to, plus stdin for input.
- redirection — Sending a command's output into a file instead of the terminal: > replaces the file, >> appends to the end of it.
- Falco field — A named value Falco attaches to each event, such as proc.pname for the parent process name or fd.name for a file or connection.
- system call — A request a program makes to the kernel, such as open this file or start a new process.
- half-open connection — A TCP connection that one side still thinks is open although the other side has gone away without closing it.
- os.Open — The Go function that opens a file for reading and returns an *os.File you can stream from and must close.
- defer — A Go statement that schedules a function call to run when the surrounding function returns, used for cleanup such as closing a file.
- message body — The data carried after the headers in an HTTP request or response, such as a JSON document.
- process — A program that is currently running, with its own memory and a numeric identifier.
- deleted but open file — A file whose last name has been removed but whose data still uses disk space because a process keeps it open.
- network socket — One end of a two-way network connection between programs, identified by an IP address and a port number.
- EMFILE — The error code meaning a process has hit its limit on open file descriptors, printed as "too many open files".
- FileHandle — The object fs/promises open() returns for an open file, wrapping its file descriptor with promise-based read, write and close methods.
- open file limit — The most file descriptors one process may have open at once, set by the operating system and shown by ulimit -n.
Taught in
- Standard Input, Output And Error — Bash Scripting & Command Line Automation
- Redirection: Truncate, Append, Both Streams — Bash Scripting & Command Line Automation
- Runtime Anomaly Detection with Falco & eBPF — Cloud Security & DevSecOps Engineering
- Bidirectional WebSockets: Reconnection & Heartbeats — Production Full-Stack Engineering
- Files and the os Package — Concurrent Systems Programming with Go
- Layers And Addresses — ISC2 Certified in Cybersecurity (CC) Exam Prep
- What A Kernel Does, And What It Refuses To Do — Linux Fundamentals & Systems Administration
- Inodes, Hard Links And What rm Removes — Linux Fundamentals & Systems Administration
- What A Process Is — Linux Fundamentals & Systems Administration
- Running Out Of Space: df, du And Inodes — Linux Fundamentals & Systems Administration
- libuv Architecture: Event Demultiplexer & Thread Pool — Node.js Internals & Backend Services
- Poll & Check Phases: I/O Callbacks & setImmediate — Node.js Internals & Backend Services
- Close Phase & Signal Dispatch: Sockets & Teardown — Node.js Internals & Backend Services
- Asynchronous File I/O: node:fs/promises & Handles — Node.js Internals & Backend Services
- Directory Traversal: Recursive Readdir & fs.watch — Node.js Internals & Backend Services
- Worked Design Two: A Global Chat System — Scalable System Design & Distributed Architecture
- Network Troubleshooting: The Ladder From Link To Port — Linux Foundation Certified System Administrator (LFCS) Exam Prep
- Constraints: Limits, Control Groups And Listeners — Linux Foundation Certified System Administrator (LFCS) Exam Prep
- Disk Full At Three In The Morning — Linux Foundation Certified System Administrator (LFCS) Exam Prep
- User Limits: Who Gets Which Number At Login — Linux Foundation Certified System Administrator (LFCS) Exam Prep