Consider three CPU-intensive processes, which require , and time units and arrive at times , and , 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.
View worked solution
Answer: B
To find the number of context switches, we trace the execution of the processes using the Shortest Remaining Time First (SRTF) scheduling algorithm, which is a preemptive version of Shortest Job First (SJF).
Let the three processes be and with their respective arrival times () and burst times ():
- : ,
- : ,
- : ,
Execution Trace:
- At : Only has arrived. starts execution.
Remaining time: . - At : arrives.
Remaining times: , .
Since has the shorter remaining time (), continues execution. No context switch occurs. - At : arrives.
Remaining times: , , .
Since still has the shortest remaining time (), continues execution. No context switch occurs. - At : finishes execution.
The scheduler selects the process with the shortest remaining time among the ready processes ( and ).
Since () is shorter than (), is scheduled.
Context Switch 1: . - At : finishes execution.
Only remains in the queue, so is scheduled.
Context Switch 2: . - At : finishes execution.
As specified, we do not count the context switches at time (start) and at (end). Therefore, the total number of context switches is 2.
Free practice · Your answers on this page are not saved.
