问题
The shortest job first algorithm is shown in the following image:
If it is shortest job first/shortest process next, shouldn't the order be:
P1 → P5 → P3 → P4 → P2 ? Since that's the order of lowest to highest service times.
Why does process 2 come second?
I know if we use burst times instead, that would be the order, but I have no idea what the differences between service time and burst times are.
Any help would be much appreciated explaining that graphic.
回答1:
The image in the question follows the correct order which is:
P1 → P2 → P5 → P3 → P4
Explanation:
P1
is arrived at time = 0
, so it will be executed first. Service Time of this process is 3
. So this process is completed at time=3
.
At time=3
, there is only one process that is arrived which is P2
. All other processes arrive later. So this process is now executed. Service time of this process is 6
, so this process is completed at time=3+6=9
.
Now at time=9
, there are three processes which are P3
, P4
and P5
(which arrived at time= 4, 6 and 8
respectively). Since the service time of P5
is 2
which is minimum as compared to that of P3
and P4
, so P5
is now executed and it gets completed at time=9+2=11
.
At time=11
, we have two processes which are P3
and P4
(which are arrived at time= 4 and 6
respectively). Since the service time of P3
is 4
which is less as compared to that of P4
, so P4
is executed now and it gets completed at time= 11+4=15
At time=15
, we have only one process which is P4
. So it is executed now. Since service time of this process is 5
, so it gets completed at time = 15+5 = 20
来源:https://stackoverflow.com/questions/42514363/understanding-the-shortest-job-first-algorithm-non-preemptive