Three CPU-bound tasks, with execution times of 15, 12 and 5 time units…
2020
Three CPU-bound tasks, with execution times of 15, 12 and 5 time units respectively arrive at times 0, t and 8, respectively. If the operating system implements a shortest remaining time first scheduling algorithm, what should be the value of t to have 4 context switches ? Ignore the context switches at time 0 and at the end.
- A.
0 < t < 3
- B.
t = 0
- C.
t < = 3
- D.
3 < t < 8
Attempted by 139 students.
Show answer & explanation
Correct answer: A
To achieve exactly 4 context switches under Shortest Remaining Time First (SRTF), we analyze the task arrivals and preemptions. Task P1 (15 units) starts at time 0. For a switch to occur, P2 must arrive and preempt P1 before P1 finishes. This requires P2's arrival time t to be less than 3 (since P1 needs 3 units to finish before P2's remaining time of 12 becomes relevant). If t=0, P2 starts immediately, reducing switches. Thus, 0 < t < 3 is required for the first switch.\nAt time 8, P3 (5 units) arrives. For another preemption, P2 must still be running and have more remaining time than P3. Since P2 arrives at t < 3, by time 8 it has run for (8-t) units. Its remaining time is 12 - (8-t) = 4 + t. For P3 to preempt, we need 5 < 4 + t, implying t > 1. Combining these conditions (t > 1 and t < 3) gives the valid range. Option A covers this necessary interval, while Option C incorrectly includes t=0 (fewer switches) and t=3 (no preemption). Option D excludes valid values below 3.
A video solution is available for this question — log in and enroll to watch it.