A pipe is used for connecting two processes. The output from one process can be sent as an input to another process. The flow is unidirectional, that is, one process can write to the pipe and another process can read from the pipe. Writing and reading are done in an area of main memory, which is also known as a virtual file. Pipes have a First in First out (FIFO) or a queue structure, that is, what is written first will be read first.
A process should not try to read from the pipe before something is written into it, otherwise it will suspend until something is written into the pipe.
Here is its syntax:
int pipe(int arr[2]);
Here, arr[0] is the file descriptor for the read end of the pipe, and arr[1] is the file descriptor for the write end of the pipe.
The function returns 0 on success and -1 on error.