operating-systems

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

  1. Save Context: Store PC, SP, registers into PCB
  2. Update State: Change process to Ready or Blocked in process table
  3. Select Next: Scheduler chooses next process from Ready queue
  4. Memory Switch: Update MMU (e.g., page directory register), typically flushes TLB
  5. Restore Context: Load new process’s PCB into CPU
  6. 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