File Descriptor:
Linux file descriptors are non-negative integers that help in identifying an open file within a process while using input/output resources like network sockets or pipes.
It can be considered as an index table of open files.
A kernel creates an FD whenever it encounters an open call.
- each UNIX process would have three standard file descriptors.
- standard input: FD 0
- standard output: FD 1
- standard error: FD 2
By default, they are connected to your terminal device (e.g., /dev/tty) but shells will allow you to set up connections between these handles and specific files and/or devices (or even pipelines to other processes) before your process starts.
Streams and file descriptors, both can represent a device connection, however, for controlling specific devices, file descriptors need to be used.
FD is used by the kernel as an index in the file description table in order to determine which process originally opened a specific file and then allow performing the requested operations on the opened device or file.
Similarly, when you open a network socket, it is also represented by an integer and it is called Socket Descriptor.
When a process makes a successful request to open a file, the kernel returns a file descriptor which points to an entry in the kernel’s global file table. The file table entry contains information such as the inode of the file, byte offset, and the access restrictions for that data stream
Pipes:
A pipe is a form of redirection that is used in Linux and other Unix-like operating systems to send the output of one program to another program for further processing. Pipes are used to create what can be visualized as a pipeline of commands, which is a temporary direct connection between two or more simple programs.
Streams:
Streams can travel through several Linux stream-pipe connections of incremental commands to accomplish administrative tasks. In the Linux command-line interface, operators like the pipe (|) and redirect (< and >) control input and output streams.