Topic 3.3 · Process & Thread Management

Schedulers, Swapping, Context Switching, Orphan & Zombie Processes

4 min read1 question to test yourself

1Definition

Swapping is a memory management mechanism where a medium-term scheduler temporarily moves inactive processes out of primary RAM onto secondary disk storage (Swap-Space) to free memory. Context Switching is the procedure of saving the hardware execution context of a running process into its PCB and restoring the context of a new process. An Orphan Process is an active process whose parent has terminated. A Zombie Process is a terminated process whose exit status has not yet been read by its parent via wait().

2Simple Explanation

When RAM becomes overcrowded, the OS Medium-Term Scheduler steps in and "swaps out" a sleeping process to disk, freeing RAM for active tasks. Later, it "swaps in" the process back to RAM.

When switching between tasks, the CPU performs a Context Switch—a rapid state save/restore operation.

If a parent process dies while its child process is still running, the child becomes an Orphan (and is adopted by the system init/systemd process). If a child process finishes execution but its parent forgets to call wait(), the child becomes a Zombie—its execution is complete, but its ghost entry remains in the Process Table until the parent reads its exit status (a process called reaping).

3Real-Life Example / Analogy

  • Swapping: Shifting less-used paperwork off your physical desk into a filing cabinet to clear workspace, then retrieving it later.
  • Context Switch: A multitasking receptionist answering Phone Call A, placing Call A on hold while writing down notes (PCB Save), answering Phone Call B (PCB Restore), then switching back to Call A.
  • Orphan: A child at a park whose parent leaves; a park guardian (init process PID 1) steps in to adopt and supervise the child.
  • Zombie: A student who turns in their final exam paper and stands by the teacher's desk waiting for a grade receipt. Until the teacher signs the receipt (wait()), the student cannot leave the room roster.

4Diagram / Visual Representation

Swap out / Swap in · Medium-term scheduler

Dispatch · Short-term scheduler

Ready Queue
Main RAM

Suspended processes
Secondary storage

CPU Core

ZOMBIE PROCESS

Child terminates

Parent has not called wait()

Exit entry remains until reaped

ORPHAN PROCESS

Parent terminates

Child is still running

Adopted by init / PID 1

5Working / How It Works

  • Context Switch Execution:
    1. Hardware timer interrupt signals CPU core.
    2. Kernel interrupts current process (Process A).
    3. Kernel saves Process A's Program Counter, Registers, and Stack Pointer into PCB A.
    4. Kernel updates PCB A state to Ready.
    5. Short-Term Scheduler selects Process B from Ready Queue.
    6. Kernel loads CPU registers from PCB B and updates Program Counter to Process B's saved line.
    7. CPU resumes executing Process B.
  • Zombie Reaping: Child calls exit() -> Kernel marks child as Zombie state -> Kernel sends SIGCHLD signal to Parent -> Parent calls wait() system call -> Kernel reads child exit code and deletes child PCB from Process Table.

6Types / Components / Characteristics

  • Schedulers Comparison:
Scheduler Type Name Core Responsibilities Frequency of Action
Long-Term Scheduler (LTS) Job Scheduler Selects jobs from disk pool; loads into RAM Ready Queue Infrequent (Seconds / Minutes)
Short-Term Scheduler (STS) CPU Scheduler Selects process from Ready Queue; dispatches CPU core Extremely Frequent (Milliseconds)
Medium-Term Scheduler (MTS) Swapper Swaps processes out of RAM to Disk to control memory Moderate (As memory pressure requires)
  • Process Anomalies:
    • Orphan Process: Parent process terminated; child adopted by init (PID 1), which automatically calls wait() upon child completion.
    • Zombie Process: Child terminated; parent has not called wait(). Consumes Process Table entries but zero CPU/RAM resources.

7Solved Examples / Problems

Problem: Why is context switching considered pure OS overhead? Solution: During a context switch, the CPU spends time saving registers, updating PCB records, invalidating memory caches, and flushing TLB buffers. During these microseconds, the system performs zero useful application computations. Thus, context switching time represents pure administrative overhead.

8Advantages, Disadvantages & Applications

  • Swapping Advantages: Increases Virtual Memory space beyond physical RAM limitations.
  • Disadvantages: Excessive swapping slows system performance to a crawl (Disk I/O latency).
  • Zombie Process Hazard: If a server program leaks thousands of zombie processes, the kernel runs out of Process IDs, preventing any new programs from launching.

9Important Points to Remember

  • Process Context Switching flushes the CPU cache and updates memory address spaces (Slow).
  • init (PID 1) is the grandmother process of all Unix systems that adopts orphan processes.

10Test Your Understanding

  1. MCQ: What happens to an Orphan process when its original parent process terminates?
    • A) It is immediately killed by the kernel.
    • B) It is adopted by the init process (PID 1).
    • C) It transforms into a Zombie process permanently.
    • D) It is swapped out to secondary disk storage.
    Show answer
    B.
  2. Conceptual Question: Explain the precise process by which a Zombie process is eliminated ("reaped") from the system process table.
  3. Application Question: Contrast the operational roles and action frequencies of Long-Term, Short-Term, and Medium-Term Schedulers.

Finished this topic?

0 of 27 topics read in Operating Systems

Handwritten notes for the exam

Unit-wise SPPU notes and PYQs for this subject.

Helpful? Share it with your class

Free for everyone, no login needed.

Share topic