Consider three CPU-intensive processes, which require 10,20 and 30 time units…

2006

Consider three CPU-intensive processes, which require 10,20 and 30 time units and arrive at times 0,2 and 6, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.

  1. A.

    1

  2. B.

    2

  3. C.

    3

  4. D.

    4

Attempted by 118 students.

Show answer & explanation

Correct answer: B

Under Shortest Remaining Time First (SRTF) scheduling, we track the remaining time of each process.

1. T=0: P1 arrives (10 units). Runs. 2. T=2: P2 arrives (20 units). P1 rem 8 < P2 rem 20. P1 continues. 3. T=6: P3 arrives (30 units). P1 rem 4 < P3 rem 30. P1 continues. 4. T=10: P1 finishes. Switch to P2 (Switch 1). 5. T=30: P2 finishes (ran for 20 units). Switch to P3 (Switch 2). 6. T=60: P3 finishes.

Excluding start and end, total context switches = 2.

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

Explore the full course: Gate Guidance By Sanchit Sir