Abstract
- Communication is essential to coordinate activities among processes or threads that cooperate to complete a task. IPC (Inter-Process Communication) allows two isolated processes or multiple threads within a single process to communicate with each other
Important
There are two primary categories of IPC: Shared Memory and Message Passing.
We also utilize Synchronisation (同步) methods like Mutex (互斥体) and Semaphore (信号量) to prevent Race Condition (竞态条件).
Shared Memory
- A shared memory location exists in the Address Space of two processes
- A System Call (系统调用) is required only to set up this shared memory. Subsequent communication between processes does not require further system calls
Important
Since the Kernel does not manage the shared memory, both processes must agree on the format and conventions for writing to it.
Most importantly, Synchronisation (同步) is required to avoid concurrent writes, which could result in overwritten or inconsistent changes.
Message Passing
- The Address Space of each Process (进程) remains separate, and the processes communicate by sending messages
- Common implementations of message passing include Pipe (管道), Socket, Upcall, and RPC (Remote Procedure Call)
Important
A mailbox exists between the two processes, residing in the kernel’s address space. Therefore, each process must use System Calls (系统调用) to send and receive messages. This makes message passing slower than Shared Memory, as communication always requires invoking system calls.
For unidirectional communication, one queue is sufficient. For bidirectional communication, two queues are required.
Listening port
A listening port is a message passing queue maintained by a process to receive messages from multiple processes.
It is used to handle requests for establishing new communication links between processes.