In computer programming, standard streams refer to the pre-connected I/O (input/output) communication channels between a program (/process) and its environment. Originally, I/O was carried out via physically connected system console / terminal with input supplied by the keyboard and output sent to the monitor, but standard streams abstract this.
There are always three default files open, stdin (the keyboard), stdout (the screen), and stderr (error messages output to the screen), each with a specific number:
- 0 - stdin - default: keyboard
- 1 - stdout - default: screen
- 2 - stderr - redirects to screen
*note: std = standard
You may have heard: "Everything in *nix is a file". By convention in UNIX and Linux, data streams and peripherals (device files) are treated as files, in a fashion analogous to ordinary files.
A file descriptor is simply a number that the operating system assigns to an open file to keep track of it.
Moreover, a file descriptor (FD or, less frequently, fildes) is an abstract indicator (handle) used to access a file or other input/output resource, such as a pipe or network socket.