Date: September 1, 2024
Topic: Inter Process Communication (IPC)
Recall
Types of IPCs:
- Message-passing IPC (OS manages sending and receiving)
- Shared memory IPC (shared channel through process address space)
Message passing uses a channel which the OS manages, allowing for common APIs but incurring overheads
Shared memory doesn’t have any overhead as there is a direct link, but is more error-prone and reimplementation is required since fixed and well-defined APIs for OS is not used
Notes
Inter Process Communication (IPC)
Multiple processes have to interact to allow a more complex multi-process application
- OS separate processes with protection mechanisms by controlling amount of CPU a process gets and maintains separate address spaces
- Inter-process communication has to get around these mechanisms
IPC Mechanisms:
- Transfer data/info between address spaces
- Maintain protection and isolation
- Provide flexibility and performance
Message-passing IPC:

write / read through a channel (shared buffer) between processes
- OS provides communication channel (e.g., a shared buffer)
- Processes write/ read messages to/from a channel
Advantages:
- The OS manages the sending and receiving processes from the communication channel
Disadvantages:
- However there is some overhead:
- We have to copy from the user space into the channel in the OS in kernel memory
- Copy back from kernel into user space (into address space of second process)
Shared Memory IPC

Direct shared memory channel
- OS establishes a shared channel and maps it into each process address space
- Processes directly read/write from this memory
Advantages:
- OS is out of the way and thus no overheads
Disadvantages:
- However, have to re-implement code as it doesn’t support fixed and well-defined APIs
<aside>
💡
While shared memory data exchange may be cheap as no copying is required, the operation of mapping memory between two processes can be expensive.
Only efficient if that setup cost can be amortized (spread out) across a sufficiently large number of messages
</aside>
<aside>
📌 SUMMARY: IPC can be done through message-passing, requiring context switching; or through shared-memory, which has a direct channel but requires memory mapping
</aside>