Operating Systems · Process Synchronization Basics
Inter-Process Communication and Need for Cooperation
Overview
Processes normally run in isolation, each inside its own protected memory, and this causes no problems.
Problems begin when processes must exchange data, either to cooperate on a task or to compete for a shared resource, because they then communicate through shared memory where simultaneous access can corrupt data.
Key concepts
- Throughput: the number of processes finished per unit time. If 7 processes finish in 25 time units, throughput is processes per unit time.
- Process memory image: each process has its own code and static variables, its own stack, and its own heap.
- Protection / security by the OS: the operating system ensures a running process accesses only the memory allocated to it.
Process P1 must not refer to memory outside P1's region, and P2 must not use anything outside P2's region. - Inter-process communication (IPC): communication between processes.
In operating systems the focus is mainly on processes running on the same computer (host); in computer networks the processes are on different hosts and use protocol stacks such as ISO OSI and TCP/IP. - Cooperation: a task is divided so that P1 does some work and P2 uses P1's output. P1 produces output; P2 takes that output as input and produces the final output. This pattern occurs in many applications.
- Competition: P1 and P2 both want to access the same resource, for example a printer, and both try to access it simultaneously.
- Shared memory: a common memory space provided for communication. P1 writes its output into shared memory and P2 reads from it.
How it works
- If P1 and P2 run independently, each using only its own code, static variables, stack, and heap, there is no problem.
- As long as the OS protects each process's memory space from other processes, independent execution is safe.
- The problem arises when two processes must exchange data. In an OS this happens between processes on the same computer, unlike network IPC where the processes are on different hosts.
- Processes communicate because they cooperate (one uses the other's output) or compete (both want the same resource, such as a printer).
- Communication uses shared memory: P1 writes its output there and P2 reads from it.
- Safe case: if P1 finishes writing and only then P2 starts reading, there is no problem.
- Unsafe case: if both run simultaneously and P1 is still writing while P2 reads from the same shared memory, a problem can occur.
- Competing for a printer through a shared buffer: both processes put their data into a memory area/buffer that must be printed, and another process takes this data and prints it.
If both write data at the same time into that memory, one process's data may be overwritten and lost. - Consequence: whenever two processes cooperate or compete and communicate through shared memory, there is a chance of data inconsistency or other errors.
Formulas
-
- number of processes finished: count of processes completed in the interval
- total time: length of the interval
- Example: 7 processes finished in 25 time units → throughput .
Worked examples
Throughput: 7 processes finish in 25 time units, so throughput processes per unit time.
Comparison
| Aspect | IPC in operating systems | IPC in computer networks |
|---|---|---|
| Location of processes | Same computer/host | Different hosts |
| Main concern | Processes on the same machine communicating | Processes on different machines communicating |
| Example mechanism mentioned | Shared memory | Protocol stack such as ISO OSI, TCP/IP |
| Reason for communication | Cooperation or competition for resources | Communication between processes on different hosts |
| Situation | Communication pattern | Result |
|---|---|---|
| Independent processes | P1 uses only its own memory, P2 uses only its own memory | No problem if OS provides protection |
| Cooperative processes, sequential | P1 finishes writing, then P2 reads | Safe |
| Cooperative processes, simultaneous | P1 writes while P2 reads simultaneously | Possible inconsistency/error |
| Competing processes on printer buffer | Both write print data at the same time | One process's data may be overwritten and lost |
Revision summary
- Throughput is completed processes per unit time, e.g. .
- Every process has its own code/static variables, stack, and heap; the OS protects each process's memory so it accesses only its own region.
- Independent processes create no communication problems.
- Processes communicate to cooperate or to compete.
- Sequential write-then-read through shared memory is safe; simultaneous write-and-read can be unsafe.
- Simultaneous access to a shared print buffer can overwrite data and lose one process's output.
- Shared-memory communication can lead to data inconsistency and other errors.
Previous-year exam insights
- IPC has two fundamental models: shared memory (processes read/write a common region; fast, but requires explicit synchronization) and message passing (processes exchange messages via send/receive primitives, no shared address space needed; works across machines).
Asked inUGC NET 2019 - Remote Procedure Call (RPC) is a message-passing-based IPC mechanism that lets a process on one machine invoke a procedure on a process on another (remote) machine, hiding the communication details; it is used for communication between processes on separate systems.
Asked inISRO 2020 - The producer-consumer (bounded-buffer) problem: a producer inserts items into a shared buffer and a consumer removes them; correctness requires the producer to wait when the buffer is full and the consumer to wait when it is empty, and buffer operations must be mutually exclusive.
Asked inISRO 2018 - Increasing the number of shared buffers in a producer-consumer system generally increases throughput (producer and consumer wait less often) and decreases the likelihood of the producer/consumer blocking, but does not by itself guarantee correctness without synchronization.
Asked inISRO 2018 - The parbegin/parend construct executes its constituent statements concurrently; a set of processes can be expressed with parbegin/parend alone only if their precedence graph is properly nested (series-parallel, built from sequential composition and parallel composition).
Graphs such as the 'N' pattern (S1→S3, S2→S3, S2→S4) cannot be expressed without extra synchronization such as semaphores or fork/join.
Asked inGATE 1991 - Cooperation between processes can be indirect (sharing a common resource such as a buffer or file) or direct (one process explicitly sends to or receives from another); both require synchronization to avoid race conditions on shared data.