BCS401 Operating System Semester IV · AY 2025-26 onward
Unit 1 · Introduction & OS Structure

Lecture 7: Multiprocess vs multithreaded systems

Learning outcomes

  • Contrast multiprocess and multithreaded systems and discuss their use cases.

Prerequisites

-- Basic idea of a <strong>process</strong> (program in execution) and CPU scheduling. -- Basic understanding of memory (address space), files, and I/O. -- Lecture 6 recap: multiprocessor (hardware) vs multiuser (OS access).

Lecture Notes

Main content

Unit 1 — Introduction & OS Structure

Lecture 7: Multiprocess vs Multithreaded Systems

Learning Outcome

Differentiate clearly between multiprocess and multithreaded systems, and select an appropriate approach for common software scenarios.


1) First fix the meaning (students often mix these)

These terms describe parallelism at different layers: multiprocess is about running multiple independent processes, while multithreaded is about multiple execution paths (threads) inside one process.:contentReference[oaicite:2]{index=2}

Term What it means Layer
Multiprocess OS manages multiple processes (multiple programs in execution) concurrently. OS scheduler + separate address spaces
Multithreaded One process contains multiple threads of execution working concurrently. Application design + OS thread support

2) What is a Process (Multiprocess view)

A process is a program in execution, including program code, current activity (program counter and registers), stack, data section, and heap.:contentReference[oaicite:4]{index=4}

2.1 Process characteristics (why “heavyweight”)

  • Separate address space: strong isolation—one process cannot directly access another’s memory.
  • PCB (Process Control Block): OS stores state, program counter, registers, open files, etc.:contentReference[oaicite:5]{index=5}:contentReference[oaicite:6]{index=6}
  • Context switching cost: saving/restoring process state and memory-management context is relatively expensive.:contentReference[oaicite:7]{index=7}

2.2 Communication between processes

Because processes are isolated, they typically communicate using OS mechanisms such as message passing (pipes, queues, sockets) or shared memory segments.:contentReference[oaicite:8]{index=8}

Why multiprocess is used:

Separate processes improve modularity and fault isolation: if one process crashes, others can continue.:contentReference[oaicite:9]{index=9}


3) What is a Thread (Multithreaded view)

A thread is the basic unit of CPU utilization. It has its own thread ID, program counter, register set, and stack, but shares the process’s code section, data section, and OS resources like open files and signals.

3.1 What threads share vs what they keep private

  • Shared (within the same process): code, global data, heap, open files/signals.
  • Private (per thread): thread ID, program counter, register set, stack.

3.2 Benefits of multithreading

  • Responsiveness: one thread can keep UI responsive while another does work.
  • Resource sharing: threads share memory naturally—less IPC overhead.
  • Economy: threads are typically cheaper to create/switch than processes.
  • Scalability: threads can run in parallel on multicore systems.
Risk (must mention):

Because threads share memory, incorrect synchronization can cause race conditions and inconsistent data. (We cover synchronization properly in later units.)


4) Multiprocess vs Multithreaded — Strong Comparison Table

Feature Multiprocess (Multiple Processes) Multithreaded (Multiple Threads in One Process)
Memory Separate address space per process (strong isolation).:contentReference[oaicite:14]{index=14} Shared address space within a process; each thread has its own stack/PC/registers.
Communication IPC required: pipes, sockets, message queues, shared memory, etc.:contentReference[oaicite:16]{index=16} Direct shared variables (needs synchronization).
Context switch cost Higher (process state + memory context).:contentReference[oaicite:18]{index=18} Lower (thread state: registers/stack/PC).
Fault isolation High: crash in one process usually does not kill others.:contentReference[oaicite:20]{index=20} Lower: a serious bug in one thread can crash the whole process (shared memory).
Best for Modular systems, strong isolation, security boundaries (services separated).:contentReference[oaicite:21]{index=21} High responsiveness and shared-data parallel tasks within one application (browser, editors).

5) Visual: Multiprocess vs Multithreaded

Multiprocess (Multiple Processes) Each process has its own address space Process P1 Code/Data/Heap Own Stack Process P2 Code/Data/Heap Own Stack Multithreaded (Threads in One Process) Threads share code/data/heap, each has its own stack Single Process Shared: Code + Data + Heap + Open Files Stack T1 Stack T2 Stack TN
Fig 7.1: Processes isolate memory; threads share memory inside one process.

6) Key Takeaways (must remember)

  • Process = isolation and safety (but heavier).
  • Thread = shared-memory concurrency (lighter, faster switching) but needs synchronization.
  • Modern systems use both: a multi-process application can also be multithreaded.

7) Quick Self-Check Questions

  1. Write two differences between a process and a thread.
  2. Why is a process considered “heavyweight” compared to a thread?
  3. Why does a multithreaded program need synchronization more urgently?
  4. Give one real-life example where multiprocess design is better, and one where multithreading is better.

Worked Example

Worked Example: Web Server — Process-per-request vs Thread-per-request

Consider a busy web server that must handle many clients at the same time. A traditional approach is to create a separate process for each request, but a more efficient approach is to create threads within a single server process. The OS book explains that process-per-request was common before threads became popular.

A) Multiprocess approach (Process-per-request)

  • For each client request, server creates a new process.
  • Pros: strong isolation; crash in one request-handler may not crash others.
  • Cons: higher overhead (process creation + IPC + heavier context switches).:contentReference[oaicite:24]{index=24}

B) Multithreaded approach (Thread-per-request)

  • One server process; each request handled by a separate thread.
  • Pros: shared memory makes sharing caches/session data easier; thread switching is lighter.
  • Cons: needs careful synchronization for shared structures (cache, request queue, logs).
Conclusion:

If you need maximum isolation, prefer multiprocess design. If you need shared-data speed and responsiveness, prefer multithreading—provided synchronization is correct.

One-Page Summary

One-Page Summary — Multiprocess vs Multithreaded

  • Multiprocess system: OS runs multiple processes concurrently; processes have separate address spaces and communicate via IPC.:contentReference[oaicite:26]{index=26}
  • Process definition: program in execution with code, program counter/registers, stack, data section, heap.:contentReference[oaicite:27]{index=27}
  • Thread definition (book): basic unit of CPU utilization; has thread ID, PC, registers, stack; shares code/data/resources with threads of same process.
  • Multiprocess advantages: modularity, fault isolation, security boundaries; but heavier overhead.:contentReference[oaicite:29]{index=29}
  • Multithreading advantages: responsiveness, resource sharing, economy, scalability; but needs synchronization due to shared memory.
  • Best one-liner: Multiprocess = isolation-first; Multithreaded = sharing-and-speed-first (with correct synchronization).