Question
An operating system uses shortest remaining time first scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds):
| Process | Arrival Time | Burst Time |
|---|---|---|
| P1 | 0 | 12 |
| P2 | 2 | 4 |
| P3 | 3 | 6 |
| P4 | 8 | 5 |
The average waiting time (in milliseconds) of the processes is _____.
Official answer and solution
- Official answer
- 5.5
- From
- Official GATE 2014 answer key
Solution
Simulate preemptive Shortest Remaining Time First (SRTF) scheduling to build the Gantt chart and compute individual and average waiting times.
We trace execution cycle by cycle according to SRTF:
- : arrival , burst
- : arrival , burst
- : arrival , burst
- : arrival , burst
-
Gantt Chart Construction:
- Time to : Only is present. runs for ms (remaining: ).
- Time : arrives with burst . Since remaining time of () < remaining time of (), is preempted and runs.
- Time : arrives with burst . has remaining , so continues.
- Time : finishes (total run ms). Ready queue: (burst ), (remaining ). has shorter remaining time (), so starts running.
- Time : arrives with burst . At this instant, has run from to ( ms), so has remaining time ms. Since remaining time of () < burst of (), is NOT preempted and continues running.
- Time : finishes (total run ms). Ready queue: (remaining ), (remaining ). runs ().
- Time : finishes (total run ms). resumes with remaining ms.
- Time : finishes.
Gantt chart:
P1 (0..2) | P2 (2..6) | P3 (6..12) | P4 (12..17) | P1 (17..27) -
Completion and Waiting Times:
- : Completion = . Turnaround = . Waiting time = .
- : Completion = . Turnaround = . Waiting time = .
- : Completion = . Turnaround = . Waiting time = .
- : Completion = . Turnaround = . Waiting time = .
-
Average Waiting Time:
5.5
Preempting P3 at t = 8 by mistakenly comparing P4's burst (5) with P3's original burst (6) instead of P3's remaining burst (4).
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2014 Computer Science and Information Technology (CS) Session 3
- Question
- 42 of 65, printed as CS Q.32
- 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.