1. Gyanastra
  2. Operating Systems
  3. Process Synchronization Basics
  4. Inter-Process Communication and Need for Cooperation
Free lesson, no account needed 6 min read 7 practice questions after it
Asked in past papers7 times
  • GATE CSE1994199219911989
  • ISRO20202018
  • UGC NET2019

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 7/257/25 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

  1. If P1 and P2 run independently, each using only its own code, static variables, stack, and heap, there is no problem.
  2. As long as the OS protects each process's memory space from other processes, independent execution is safe.
  3. 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.
  4. Processes communicate because they cooperate (one uses the other's output) or compete (both want the same resource, such as a printer).
  5. Communication uses shared memory: P1 writes its output there and P2 reads from it.
  6. Safe case: if P1 finishes writing and only then P2 starts reading, there is no problem.
  7. Unsafe case: if both run simultaneously and P1 is still writing while P2 reads from the same shared memory, a problem can occur.
  8. 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.
  9. Consequence: whenever two processes cooperate or compete and communicate through shared memory, there is a chance of data inconsistency or other errors.

Formulas

  • Throughput=number of processes finishedtotal time\text{Throughput} = \dfrac{\text{number of processes finished}}{\text{total time}}
    • 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 =7/25= 7/25.

Worked examples

Throughput: 7 processes finish in 25 time units, so throughput =7/25= 7/25 processes per unit time.

Comparison

AspectIPC in operating systemsIPC in computer networks
Location of processesSame computer/hostDifferent hosts
Main concernProcesses on the same machine communicatingProcesses on different machines communicating
Example mechanism mentionedShared memoryProtocol stack such as ISO OSI, TCP/IP
Reason for communicationCooperation or competition for resourcesCommunication between processes on different hosts
SituationCommunication patternResult
Independent processesP1 uses only its own memory, P2 uses only its own memoryNo problem if OS provides protection
Cooperative processes, sequentialP1 finishes writing, then P2 readsSafe
Cooperative processes, simultaneousP1 writes while P2 reads simultaneouslyPossible inconsistency/error
Competing processes on printer bufferBoth write print data at the same timeOne process's data may be overwritten and lost

Revision summary

  • Throughput is completed processes per unit time, e.g. 7/257/25.
  • 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.
Pages 1–2 of 2