Inter Process Communication (IPC) in Linux is a critical mechanism that allows processes to exchange data and synchronize their actions. It enables different processes to communicate and share information, whether they are related or not. IPC is essential for efficient system operation, especially in environments where multiple processes need to collaborate. In Linux, IPC can be achieved using various methods such as pipes, named pipes (FIFO), message queues, shared memory, semaphores, and signals. These methods allow processes to send and receive data, synchronize their operations, and manage resources effectively. Understanding IPC is vital for developing multi-process applications, improving system performance, and ensuring proper resource management in Linux-based environments.
Following are some important terms that we need to know before proceeding further on this
topic.
Pipes: Communication between two related processes. The mechanism is half duplex meaning the first process communicates with the second process. To achieve a full duplex i.e., for the second process to communicate with the first process another pipe is required.
FIFO: Communication between two unrelated processes. FIFO is a full duplex, meaning the first process can communicate with the second process and vice versa at the same time.
Message Queues: Communication between two or more processes with full duplex capacity. The processes will communicate with each other by posting a message and retrieving it out of the queue. Once retrieved, the message is no longer available in the queue.
Shared Memory: Communication between two or more processes is achieved through a shared piece of memory among all processes. The shared memory needs to be protected from each other by synchronizing access to all the processes.
Semaphores: Semaphores are meant for synchronizing access to multiple processes. When one process wants to access the memory (for reading or writing), it needs to be locked (or protected) and released when the access is removed. This needs to be repeated by all the processes to secure data.
Signals: Signal is a mechanism to communication between multiple processes by way of signaling. This means a source process will send a signal (recognized by number) and the destination process will handle it accordingly.
Before we go into process information, we need to know a few things, such as – What is a process? A process is a program in execution.
What is a program? A program is a file containing the information of a process and how to build it during run time. When you start execution of the program, it is loaded into RAM and starts executing.
Each process is identified with a unique positive integer called as process ID or simply PID
(Process Identification number). The kernel usually limits the process ID to 32767, which is
configurable. When the process ID reaches this limit, it is reset again, which is after the
system processes range. The unused process IDs from that counter are then assigned to
newly created processes.
Different processes running on an OS are logically independent and isolated entities.
They have separate logical memory spaces, CPU states, open files etc.
An event in one process does not interfere with another process. One process may crush but the other processes will continue to run.
But often it is also necessary for two processes or a process and the OS to interact. There are several reasons for that.
It may be necessary to pass the output of one process as the input to another process.
In a multiple processor system, dividing a job in several processes may achieve faster completion through parallelism.
Note: We will discuss all the applications of IPC in Linux one by one along with examples.
Indian Institute of Embedded Systems – IIES