File Descriptors, I/O Redirection, Processes, Network Programming and Concurrency
I like to understand how things work (together) by asking myself questions. So let’s get started.
Question 1: What is input/output?
Input/output(I/O) is the process of copying data between 1) main memory and 2) external devices such as disk drives, terminals, and networks.
1 ) An input operation copies data from an I/O device to main memory.
2 )An output operation copies data from memory to a device.
We can also say Input/output(I/O) is the process of copying data between a program/process and the external device. The reason for saying that is
1) the CPU is the one reads&interprets the machine-language instructions stores in main memory.
2 ) In the perspective of CPU, keyboard, mouse, display, disk drives, networks are all I/O devices.
Question here to ask: how to move data between 2/multiple processes?
Question 2: Why does a process need to know file descriptors?
All I/O routines centered on file descriptors.
A process performs input & output by calling the read and write functions respectively.
Every process has a current working directory. That’s why your process can refer to a specific file that relative to the current working directory.
A process opens an existing file or create a new file by calling the open function.
Sharing resources between multiple processes.
Question 3: Each process created by a Linux shell begins life with three open files: standard input (descriptor 0), standard output (descriptor 1), and standard error (descriptor 2). So where do these 3 files reside?
Reference:
Data transfer between processes
https://www.mcs.anl.gov/papers/icpp06-smp-xfer.pdf
Introduction to Linux IO Redirection
https://www.digitalocean.com/community/tutorials/an-introduction-to-linux-i-o-redirection