Reputation: 79
For example when I read about different scheduling algorithms like First-Come-First-Serve
, Shortest Job First
, Priority Scheduling
, Round Robin
scheduling for all of them the measure is average wait time.
Consider a processes with run times of 21, 3, 6, 2 (msecs). Average wait time for First-Come-First-Serve
is (0 + 21 + 24 + 30)/4 = 18.75 msecs and for Shortest Job First
is (0+2+5+11)/4 = 4.5ms.
Does this mean Shortest Job First
is better? I understand the wait time is longer in the first one but this is not busy waiting, the CPU is busy executing tasks. Like 21 msec task first, first it is completed then next to the other one etc. Like shouldn't it take same amount of time to complete the tasks no matter the order? Any ideas?
Upvotes: 1
Views: 599
Reputation: 14856
No, that does not mean shortest job first is better, SJF
minimizes the average waiting time
on the expense of fairness. All these are just measurements.
On a single processor system, yes, it will take the same time.
It all comes down to what is the purpose of the system, what are the kind of jobs that will be run.
EDIT
In linux2.6 as an example to real system, the scheduling algorithm for real tasks was SCHED_OTHER
which gave priority to processes that had a high average sleepig time. (i.e. jobs that spent most of the time sleeping waiting for some i/o). We would like to minimize their response time.
And the system shared the CPU by all the processes by giving each one a slice time, unlike RR which gives an equal slice time.
Upvotes: 2