Consider the following CPU processes with arrival times (in milliseconds) and…
2017
Consider the following CPU processes with arrival times (in milliseconds) and length of CPU bursts (in milliseconds) as given below:
Process | Arrival Time | Burst Time |
P1 | 0 | 7 |
P2 | 3 | 3 |
P3 | 5 | 5 |
P4 | 6 | 2 |
If the pre-emptive shortest remaining time first scheduling algorithm is used to schedule the processes, then the average waiting time across all processes is _______ milliseconds.
Attempted by 158 students.
Show answer & explanation
Correct answer: 3
Key result: The average waiting time is 3 milliseconds.
Step-by-step schedule under preemptive Shortest Remaining Time First (SRTF):
0–3: Process P1 runs (after 3 ms its remaining time = 4).
3: Process P2 arrives with burst 3, preempts P1 because 3 < 4.
3–6: P2 runs and finishes at time 6 (it was not preempted because its remaining time stayed shortest).
5: P3 arrives (burst 5) and waits.
6: P4 arrives with burst 2. At time 6 the remaining times are P1=4, P3=5, P4=2, so P4 runs next.
6–8: P4 runs and finishes at time 8.
8–12: P1 resumes (remaining 4) and finishes at time 12.
12–17: P3 runs and finishes at time 17.
Compute waiting time for each process (waiting = finish time − arrival time − burst time):
P1: finish 12, arrival 0, burst 7 ⇒ waiting = 12 − 0 − 7 = 5 ms
P2: finish 6, arrival 3, burst 3 ⇒ waiting = 6 − 3 − 3 = 0 ms
P3: finish 17, arrival 5, burst 5 ⇒ waiting = 17 − 5 − 5 = 7 ms
P4: finish 8, arrival 6, burst 2 ⇒ waiting = 8 − 6 − 2 = 0 ms
Average waiting time = (5 + 0 + 7 + 0) / 4 = 12 / 4 = 3 milliseconds.
A video solution is available for this question — log in and enroll to watch it.