Consider a process P running on a CPU. Which one or more of the following…

2024

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

Attempted by 307 students.

Show answer & explanation

Correct answer: A, B

Key insight: a context switch that moves a process into a non-running state happens when the process cannot continue executing and the kernel schedules someone else.

  • When the process makes a blocking system call to read from disk, it must wait for I/O to complete. The kernel marks it blocked and schedules another process — this always causes the process to move to a non-running state.

  • Other events (a page fault for a swapped-out page, a disk interrupt serving another process, or a timer interrupt) can often lead to a context switch, but none of them guarantee it in every system or situation. Whether they cause the running process to be moved off the CPU depends on OS design and scheduler decisions.

Therefore, the only event that will always trigger a context switch is: P makes a blocking system call to read a block of data from the disk.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir