1. LPU MCA Semester 1
  2. CAP366
  3. Unit 3

CAP366 · Unit 3: Process management

Context switching

10 practice questions · in the MTE and ETE syllabus

Key points

  • Save old state in PCB, load new state
  • Pure overhead
  • Cost depends on hardware and memory state
  • Thread switch is cheaper than process switch

A context switch saves the state of the running process into its PCB and loads the saved state of the next process. The time spent is pure overhead: no useful work is done. The dispatcher performs it (switching context, switching to user mode, jumping to the right location).

Cost depends on hardware support (number of registers, register sets) and the memory-management state to reload.

Example: quantum 10 ms and switch cost 2 ms gives useful time 10 / 12 = 83.3 percent. For 5 processes with 20 ms each, quantum 5 ms and switch 1 ms: 20 slices, 19 switches, total 100 + 19 = 119 ms.

SwitchRelative cost
Between processesHigher (address space changes, TLB/page tables)
Between threads of one processLower (same address space)

Exam pitfall: switches are counted between slices, so n slices give n - 1 switches; a very small quantum makes overhead dominate.

Try two questions

Question 1 · Tier 1, Recall

Context-switch time is best described as:

  1. The time a process waits in the ready queue before first running
  2. The time from submission of a job until it terminates
  3. Pure overhead during which no user process makes progress
  4. The time between a request and the first response it produces
Show the answer

C. Saving one process's state and loading another's does no useful user work, so it is overhead.

Why not A: That is waiting or response time, not the cost of switching.

Why not B: That is turnaround time.

Why not D: That is response time.

Question 2 · Tier 3, Apply

Three processes arrive at time 0 with CPU bursts of 5, 3 and 7 ms under round robin with quantum 3 ms. How many context switches occur between processes, excluding the first dispatch and the final completion?

  1. 3
  2. 5
  3. 4
  4. 6
Show the answer

C. The Gantt order is P1, P2, P3, P1, P3 across five slices, which gives 4 switches between consecutive slices.

Why not A: This misses one of the later switches.

Why not B: This counts the first dispatch as a switch.

Why not D: This counts every quantum slice as a switch, including those that do not change the process.