6
Consider a set of 5 processes whose arrival time. CPU time needed and the priority are given below
smaller the number, higher the priority.
If the CPU scheduling policy is SJF with pre-emption, the average waiting time will be
| Process Priority | Arrival Time (in ms) | CPU Time Needed (in ms) | Priority |
| P1 | 0 | 10 | 5 |
| P2 | 0 | 5 | 2 |
| P3 | 2 | 3 | 1 |
| P4 | 5 | 20 | 4 |
| P5 | 10 | 2 | 3 |
If the CPU scheduling policy is SJF with pre-emption, the average waiting time will be
Scheduling order will be
P2 , P3 , P1 , P5 , P1, P4
Waiting time of processes will be
P2 = 0
P3= 5-2=3
P1=10+2=12
P5=0
P4= 15
Average waiting time will be = (0+3+12+0+15)/5= 30/5=6ms
P2 , P3 , P1 , P5 , P1, P4
Waiting time of processes will be
P2 = 0
P3= 5-2=3
P1=10+2=12
P5=0
P4= 15
Average waiting time will be = (0+3+12+0+15)/5= 30/5=6ms

