Inter-process communication using Pipes in Linux User Space

Pipes is an inter-process communication method. Pipes are the oldest inter-process communication method in Unix. The below image depicts a basic mode of operation of a pipe. As can be seen from the image that pipe communication is uni-directional and data can only travel in a single direction in a pipe.

FIG Courtesy: Linux Programming Interface

As seen in the image, since a pipe is a byte stream, it does not follow any message boundaries. The processes that are using the pipe should handle the packet message boundaries themselves.

A pipe has a fixed buffer size and once the buffer is full, further writes to the PIPE will block or fail. A pipe can be created by using the “pipe system call”. It is provided below:

FIG Courtesy: Linux Programming Interface

The above API denotes an array parameter which can hold two file descriptors. If the call to pipe API is successful, in the array filedes[0] will be the read end of the pipe and filedes[1] will be the write end of the pipe.

A pipe can be used in inter-process communication between a parent process and a child process. In this example, the parent writes to the pipe and the child reads from the pipe. It is denoted pictorially below:

FIG Courtesy: Linux Programming Interface

Refer the programming examples provide in Linux Programming interface for Pipes. A simple program for pipes presented below

Courtesy: Linux Programming Interface

FIFO for inter-process communication in Linux User Space

Comments

  1. Pingback: Netlink Protocol Families | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *