>

Blog

Inter Process Communication (IPC)

Inter Process Communication (IPC)
What is IPC?

IPC (Inter Process Communication) is a mechanism where one process communicates with another process and can exchange information and data. There can be two types of the processes independent and co-operative. Though it may appear that processes that operate independently will perform very well, there are many situations in which the co-operative nature can be used to improve computational speed, modularity, and convenience. IPC is a method that allows processes to interact and coordinate their actions. IPC is a means for exchanging data between processes. It allows one programme to control another, allowing data to be shared without interruption. IPC allows processes to share memory and information by letting them to use segments, semaphores, and other ways. IPC makes message transfer between processes more efficient. Task Control Architecture is the foundation of IPC (TCA). It is a versatile method for sending and receiving variable-length arrays, data structures, and lists. It supports a wide range of operating systems and languages and can use the publish/subscribe and client/server data-transfer paradigms.


No alt text provided for this image

Types of IPC

IPC can be divided into two parts Shared Memory and Message Passing. We will have a look on them one by one.

Shared Memory

A shared memory is a memory that is shared by two or more processes and is created by employing shared memory across all processes. Shared memory allows the interchange of data through a defined area of memory. By synchronising access across all processes, this sort of memory must be safeguarded from each other. Communication between processes utilising shared memory necessitates the sharing of a variable, which is entirely dependent on the programmer's implementation. We must also synchronise the processes so that they do not alter the shared memory at the same time. Ex. producer-consumer problem.

Message Passing

Message passing means simply send messages to other processes or receive messages from them. Multiple processes can read and write data to the message queue without being connected to each other using the message passing mechanism. Processes communicate with one another without the use of shared memory in this method. Messages are held in the queue until they are picked up by their intended receiver. Message queues are widely utilised in most operating systems for inter process communication.


No alt text provided for this image

Why IPC?

There are a variety of reasons why data should be shared using inter-process communication. The following are some of the most important reasons:

  • It helps to speedup modularity
  • Computational speed
  • Privilege separation
  • Convenience
  • Synchronization
  • Assists operating systems in communicating with one another and synchronising their actions.
IPC in Linux

Linux provides support for many inter process communication (IPC) mechanisms. Signals, Pipes and Sockets are some of them. We will have a look on Pipes and Sockets. These mechanisms (Pipes & Sockets) are used for communication in client and server architecture. At Encoding Enhancers, we have used both of these mechanisms in our project for leak detection system.

Pipes

A pipe in Linux is made up of two file data structures that point to the same temporary VFS (Virtual File System) inode, which points to a physical page in memory. Each file data structure has pointers to two file operation procedure vectors: one for writing to the pipe and the other for reading from it. Bytes are copied into the shared data page as the writing process writes to the pipe, and bytes are copied from the shared data page as the reading process reads from the pipe. Linux needs to synchronise pipe access. It uses locks, wait queues, and signals to ensure that the reader and writer of the pipe are on the same page. For example, we have implemented this as shown below in our project:


No alt text provided for this image

Defined enum for reading and writing to the pipe.


No alt text provided for this image

These are two file descriptors defined in an array one for reading purpose and one for writing purpose.


No alt text provided for this image

In above shown images these are functions for reading and writing to the pipe.

Sockets

Sockets were first introduced in 2.1 BSD, then with 4.2BSD, they were developed into their current form. Most recent UNIX system releases now have the Sockets capability. Socket programming is a method of allowing two network nodes to communicate with one another. One socket (node) listens on a specific port at an IP address, while the other socket (node) reaches out to make a connection. While the client connects to the server, the server creates the listener socket.


No alt text provided for this image

Summary

There are many other mechanisms also for inter process communication like FIFOs, Signal and Semaphores. To pass information, IPC avoids using real disk-based files and the associated I/O overhead cost. You must first create or open the resource, then utilise and close it, just like a file. The resources have an owner, a group, and permissions, just like real files. The resource will continue to exist until you delete it. When you need to communicate with applications quickly and don't want to develop code to manage the low-level intricacies of communication between the processes, use IPCs.

Ready to discuss your project? Let's Talk Contact Us