IAE Academy

GATE 2024 CS2 Q.25: solution and answer

GATE 2024 · CS2Q.25 · 1 mark · MSQ

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. (A)

    P makes a blocking system call to read a block of data from the disk

  2. (B)

    P tries to access a page that is in the swap space, triggering a page fault

  3. (C)

    An interrupt is raised by the disk to deliver data requested by some other process

  4. (D)

    A timer interrupt is raised by the hardware

See the question in the paper

Answer and solution

ANSWER

Options (A) and (B) are correct.

Official answer: A, BSource: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. The question asks which events will always make the OS switch context so that P leaves the running state. An event that only sometimes does this is not correct.

  2. (A) A blocking system call to read a block from the disk cannot finish at once, because the disk transfer takes time. The OS moves P to the blocked state and dispatches another process, so a context switch always happens.

  3. (B) The page is in swap space, so it is not in memory. The page fault handler must start a disk read to bring it in, and P cannot continue until that I/O completes. P moves to the blocked state and the CPU goes to another process, so a context switch always happens.

  4. (C) The disk interrupt delivers data for some other process. The handler may move that process from blocked to ready, but P is still runnable. The scheduler need not preempt P, so P need not leave the CPU. Not guaranteed.

  5. (D) A timer interrupt invokes the scheduler, but the scheduler may let P continue. For example, P may be the only ready process, or its time slice may not be used up. So a context switch is not guaranteed.

  6. Only (A) and (B) force P out of the running state every time.

KEY IDEA

P always leaves the CPU when it must wait for I/O that it started itself, as with a blocking read or a page fault on a swapped-out page. Interrupts that merely invoke the scheduler or serve other processes leave the decision open.

WATCH OUT FOR

Treating a timer interrupt as always causing a context switch. It only gives the scheduler a chance to switch, and the scheduler may keep P running.

From the GATE 2024 CS2 paper. Every question of this paper · Download the full paper · All 9 Processes & threads questions, with notes

More Processes & threads questions