One mechanism that the parent and child can use to communicate is called a pipe. Just like a real physical pipe, information flows from one end to the other. Information is bidirectional. A process writes to one end of the pipe to send information and reads the other end of the pipe to receive information.
The pipe is used to copy information from the address space of one process to the address space of another process, thus allowing communication between the two processes. The Linux kernel represents the pipe as a file descriptor.
The pipe write operation is asynchronous. The read operation is blocking.
To create a pipe, a process makes the following call to the Linux Kernel:
pipe(pipeIdentifier);
A pipe created prior to the execution of the fork is known by both the parent and the child. They can, therefore, use it to communicate.
A FIFO data structure is created in the kernel. The kernel represents the pipe as a file descriptor. The file identifier pipeIdentifier[0] is a file pointer to read the end of the pipe. The file identifier pipeIdentifier[1] is a file pointer to write the end of the pipe.
If a process does not intend to use a pipe end (e.g. only read a pipe, not write it), it should explicitly close that end so that an end of file condition can be detected. Because the representation is a file descriptor, the close function is called to close the end of a pipe. Example process does not intend to read:
close (pipeIdentification[0]);
Sample code in which after a fork, the parent sends data to a child via the pipe. The child receives data from the parent and prints it.
Maintained by Barbara Bracken
Last Modified 11/07/2025
This page is copyright © by Barbara Bracken