Question
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.
Official answer and solution
- Official answer
- 3
- From
- Official GATE 2017 answer key
Solution
Simulate preemptive Shortest Remaining Time First (SRTF) CPU scheduling to compute the completion time, turnaround time, and waiting time for each process.
We are given four processes:
- P1: Arrival = 0, Burst = 7
- P2: Arrival = 3, Burst = 3
- P3: Arrival = 5, Burst = 5
- P4: Arrival = 6, Burst = 2
Trace the scheduling step by step:
- At : Only P1 is available (remaining burst = 7). P1 runs from to .
- At : P1 has remaining burst . P2 arrives with burst 3. Since , P2 preempts P1. P2 runs.
- At : P2 has remaining burst . P3 arrives with burst 5. Remaining times: P2 = 1, P1 = 4, P3 = 5. P2 continues running.
- At : P2 completes (completion time = 6). P4 arrives with burst 2. Remaining times: P4 = 2, P1 = 4, P3 = 5. P4 has the shortest remaining time, so P4 runs from to .
- At : P4 completes (completion time = 8). Remaining processes: P1 (rem = 4), P3 (rem = 5). P1 runs from to .
- At : P1 completes (completion time = 12). Only P3 remains (rem = 5). P3 runs from to .
- At : P3 completes.
Calculate turnaround and waiting times (Waiting time = Turnaround time - Burst time):
- P1: Turnaround = , Waiting =
- P2: Turnaround = , Waiting =
- P3: Turnaround = , Waiting =
- P4: Turnaround = , Waiting =
Average waiting time across all 4 processes:
3.0
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2017 Computer Science and Information Technology (CS) Session 1
- Question
- 24 of 65, printed as CS Q.24
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.