GATE CS 2024 Set 2 | Question 25

MSQ · 1 mark

Consider a process P running on a CPU. Which one or more of the following events will always trigger a context switch by the OS that results in process P moving to a non-running state (e.g., ready, blocked)?

  1. Option A: P makes a blocking system call to read a block of data from the disk (correct)
  2. Option B: P tries to access a page that is in the swap space, triggering a page fault (correct)
  3. Option C: An interrupt is raised by the disk to deliver data requested by some other process
  4. Option D: A timer interrupt is raised by the hardware

Answer

(A), (B)

Explanation

The test is whether P could carry on running after the event.

  • A: a blocking read must wait for the disk, so P is moved to the blocked state and the OS switches to another process (or the idle task). Always.
  • B: the missing page has to be read in from swap space, which is slow disk I/O, so P blocks until the page arrives. Always.
  • C: the handler marks the other process ready, but P can simply resume afterwards; P is switched out only if the scheduler decides to preempt it. Not always.
  • D: the timer handler may find that P's time slice has not run out, or that no other process is ready, and return to P. Not always.

Answer: A, B