Skip to main content
Engineering LibreTexts

5.4.3: IPC - Message Passing / Shared Memory

  • Page ID
  • IPC through Message Passing

    As we previously discussed - a process can be one of two different types:

    • Independent process.
    • Co-operating process.

    An independent process is not affected by the execution of other processes while a co-operating process can be affected by other executing processes. Though one can think that those processes, which are running independently, will execute very efficiently, in reality, there are many situations when co-operative nature can be utilised 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 co-operation between them. Processes can communicate with each other through either of these techniques:

    1. Shared Memory
    2. Message passing

    The Figure 1 below shows a basic structure of communication between processes via the shared memory method and via the message passing method.

    An operating system can implement both method of communication. First, there is the shared memory method of communication. Communication between processes using shared memory requires processes to share some variable and it is usually left up to the programmer to implement it. Sharing memory works in this manner: process1 and process2 are executing simultaneously and they share some resources. Process1 generates data based on computations in the code. Process1 stores this data in shared memory. When process2 needs to use the shared data, it will check in the shared memory segment and use the data that process1 placed there. Processes can use shared memory for extracting information as a record from another process as well as for delivering any specific information to other processes.

    Figure \(\PageIndex{1}\): Shared Memory and Message Passing. ("Shared Memory and Message Passing" by ShubhamMaurya3Geeks for Geeks is licensed under CC BY-SA 4.0)

    Second, there is communication between processes via message passing. In this method, processes communicate with each other without using any kind 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 a system's library functions send() and receive().
      We need at least two primitives:
      – send(message, destination) or send(message)
      – receive(message, host) or receive(message)

    To send a message, Process A, sends a message via the communication link that has been opened between the 2 processes. Using the send() function it send the necessary message. Process B, which is monitoring the communication link, uses the receive() function to pick up the message and performs the necessary  processing based on the message it has received. The message size can be of fixed size or of variable size. If it is of fixed size, it is easy for an OS designer but complicated for a programmer and if it is of variable size then it is easy for a programmer but complicated for the OS designer.

    Adapted from:
     "Inter Process Communication (IPC)" by ShubhamMaurya3Geeks for Geeks is licensed under CC BY-SA 4.0

    • Was this article helpful?