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)?
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