Definition
Process Switch
A process switch (context switch) is the OS operation pausing the current process and transferring control to another. Central to multitasking, it maintains the “illusion of parallelism.” A mode switch is a prerequisite.
Mechanism
Triggers
Process switch occurs when OS gains CPU control via:
- Supervisor Call: Explicit request for OS service (e.g., I/O)
- Trap: Exception from current instruction (division by zero, memory violation)
- Interrupt: External signal (timer timeout, I/O completion)
Switch Sequence
- Save Context: Store PC, SP, registers into PCB
- Update State: Change process to Ready or Blocked in process table
- Select Next: Scheduler chooses next process from Ready queue
- Memory Switch: Update MMU (e.g., page directory register), typically flushes TLB
- Restore Context: Load new process’s PCB into CPU
- Resume Execution: CPU begins executing from new process’s PC
Performance
Overhead Cost
Process switching is “pure overhead” — no useful user-level work occurs during transition. The memory switch is the primary cost: invalidating caches (TLB) causes significant penalty as hardware must fetch translations from main memory.
Factors
- Hardware support (number of registers to save/restore)
- OS efficiency in managing the process table