operating-systems

Definition

Process Switch

A Process Switch (or Context Switch) is the operation where the operating system pauses the execution of the currently running process and transfers control to another process.

Mechanism

The OS performs the following sequence:

  1. Save Context: Store the Program Counter, Stack Pointer, and Registers of the current process into its PCB.
  2. Update State: Change the process state to Ready or Blocked.
  3. Select Next: The scheduler chooses the next process from the ready queue.
  4. Restore Context: Load the hardware context from the new process’s PCB.
  5. Memory Switch: Update the memory management unit (e.g., Page Directory Base Register), which typically flushes the TLB.

Cost

Process switching is expensive due to the memory switch (Step 5), which invalidates caches (TLB), causing a performance penalty on subsequent memory accesses.