Inter-Process Communication

  • There are two types of processes: Independent and Cooperating.

    • An independent process is not affected by the execution of other processes, while a cooperating process can be affected by other executing processes.

  • there are many situations when a process’ cooperative nature can be utilized for increasing computational speed, convenience, and modularity

  • Inter-process communication (IPC) is a mechanism which allows processes to communicate with each other and synchronize their actions. The communication between these processes can be seen as a method of cooperation between them.

  • Processes can communicate with each other in two ways:

    • Shared Memory

      • Let’s say there are two processes: the Producer and the Consumer.

      • The producer produces some item and the Consumer consumes that item.

      • The two processes shares a common space or memory location known as the “buffer,” where the item produced by the Producer is stored and from where the Consumer consumes the item if needed.

      • There are two versions of this problem:

        • the first one is known as the unbounded buffer problem,

          • in which the Producer can keep on producing items and there is no limit on the size of the buffer.

        • The second one is known as the bounded buffer problem,

          • in which the Producer can produce up to a certain number of items, and after that it starts waiting for the Consumer to consume them.

          • the Producer and the Consumer will share some common memory. Then the Producer will start producing items. If the total number of produced items is equal to the size of buffer, the Producer will wait until they’re consumed by the Consumer.

          • the Consumer first checks for the availability of the item, and if no item is available, the Consumer will wait for the Producer to produce it. If there are items available, the Consumer will consume them.

    • Message Parsing.

      • processes communicate with each other without using any kind of of shared memory. If two processes p1 and p2 want to communicate with each other, they proceed as follows:

        • Establish a communication link (if a link already exists, no need to establish it again.)

        • Start exchanging messages using basic primitives. We need at least two primitives: send(message, destination) or send(message) and receive(message, host) or receive(message)

      • The message size can be fixed or variable. If it is a fixed size, it is easy for the OS designer but complicated for the programmer. If it is a variable size, then it is easy for the programmer but complicated for the OS designer. A standard message has two parts: a header and a body.

      • The header is used for storing the Message type, destination id, source id, message length, and control information. The control information contains information like what to do if it runs out of buffer space, the sequence number, and its priority. Generally, the message is sent using the FIFO style.

Last updated