Linux IPC
Pipes
In Unix-like operating systems, file descriptors (FD) are integer values that refer to open files or I/O streams. Each process has its own set of file descriptors that point to files, sockets, pipes, or other input/output resources. The file descriptors 0, 1, and 2 have special significance:
- File Descriptor 0 (stdin):
- FD 0 represents standard input (stdin). This is the default input stream for a process. When a program reads from FD 0, it reads data from the standard input, which is usually connected to the keyboard.
- File Descriptor 1 (stdout):
- FD 1 represents standard output (stdout). This is the default output stream for a process. When a program writes to FD 1, it writes data to the standard output, which is typically displayed on the terminal.
- File Descriptor 2 (stderr):
- FD 2 represents standard error (stderr). This is the default error output stream for a process. When a program writes to FD 2, it writes error messages or diagnostics to the standard error, which is also typically displayed on the terminal.
These file descriptors are set up by the operating system when a process is created. You can use these file descriptors to perform input and output operations without explicitly opening or closing files. For example, a simple command-line program might read from stdin (FD 0) and write to stdout (FD 1) or stderr (FD 2).
Here’s a brief summary:
- FD 0: Standard Input (stdin)
- FD 1: Standard Output (stdout)
- FD 2: Standard Error (stderr)
This post is licensed under
CC BY 4.0
by the author.