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 (
initprocess 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
5Working / How It Works
- Context Switch Execution:
- Hardware timer interrupt signals CPU core.
- Kernel interrupts current process (Process A).
- Kernel saves Process A's Program Counter, Registers, and Stack Pointer into PCB A.
- Kernel updates PCB A state to Ready.
- Short-Term Scheduler selects Process B from Ready Queue.
- Kernel loads CPU registers from PCB B and updates Program Counter to Process B's saved line.
- CPU resumes executing Process B.
- Zombie Reaping: Child calls
exit()-> Kernel marks child as Zombie state -> Kernel sendsSIGCHLDsignal to Parent -> Parent callswait()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 callswait()upon child completion. - Zombie Process: Child terminated; parent has not called
wait(). Consumes Process Table entries but zero CPU/RAM resources.
- Orphan Process: Parent process terminated; child adopted by
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
- 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
initprocess (PID 1). - C) It transforms into a Zombie process permanently.
- D) It is swapped out to secondary disk storage.
Show answer
B. - Conceptual Question: Explain the precise process by which a Zombie process is eliminated ("reaped") from the system process table.
- Application Question: Contrast the operational roles and action frequencies of Long-Term, Short-Term, and Medium-Term Schedulers.
