Consider three CPU intensive processes, which require 10, 20 and 30 units of…
2019
Consider three CPU intensive processes, which require 10, 20 and 30 units of time 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.
- A.
4
- B.
2
- C.
3
- D.
1
Attempted by 483 students.
Show answer & explanation
Correct answer: B
Answer: 2 context switches.
Explanation:
Processes: P1 requires 10 time units (arrives at 0), P2 requires 20 (arrives at 2), P3 requires 30 (arrives at 6).
Behavior at arrivals: At t=2 P2 arrives but P1 has 8 units remaining which is less than P2's 20, so P1 continues. At t=6 P3 arrives but P1 has 4 units remaining which is still the smallest, so P1 continues.
Resulting timeline: 0–10: P1 runs to completion. 10–30: P2 runs. 30–60: P3 runs.
Count context switches (excluding the initial start at time 0 and the final completion): switch at t=10 from P1 to P2 (1), switch at t=30 from P2 to P3 (1). Total = 2.
Therefore, the operating system performs 2 context switches under SRTF for these processes.
A video solution is available for this question — log in and enroll to watch it.