* A pipe is a method of connecting standard output of one process to a standard input of another process.
* Pipes are one of the oldest IPC mechanism that are available.
* They provide one way communication between process.
* Hence they are half duplex.
We have used pipes in shell scripting
For example: ls | sort | lp
In the above example the data is flowing in one direction. i.e from the output from “ls” is given as input to “sort” and output of sort is given as input to “lp”. Hence the data is traveling from left to right in one direction. Hence half duplex.
When a process creates a pipe, 2 file descriptor. One descriptor is used to take input into the pipe (write), while the other is used to obtain data from the pipe (read).
This process can be visually represented as below:
You might be thinking what is the practical use if the process is communicating with itself?
From the above example we can see that the pipe is connected to process itself. The data traveling will move from the kernel and back to the process. But in reality there is no point in doing the above logic. Because the pipe is going to talk to itself.
Hence we fork a child process. Since all child process will inherit any open “fd” from the parent, we now have 2 process communicating with each other. And now we have a basis for multiprocess communication.
This can be pictorially represented as below:
To send the data into pipe we use “write()”” system call. To return the data from pipe we use “read()” system call.
fd is opened for reading
fd for writing.