Our two programs need a slice of time. Winamp needs 6ms while word needs 8ms. Lets pretend we also have two other processes, (P3 and P4).

P1 (Winamp) 6ms

P2 (Word) 8ms

P3 7ms

P4 3ms

There are two ways to measure how well a scheduling algorithm is. Average wait time and total time. The most obvious way to do things is by first come first served. Lets look at this


So the average wait time is (0 + 6 + 14 + 21) / 4 = 10.25ms and total time = 24ms.

The longer a process waits on average, the more sluggish a system will feel. If Winamp was kept waiting too much (on average 10ms) it may start distorting the sound. Lets pretend that that we know long a process will take to complete beforehand. Although this is not possible in reality, it is necessary when we consider the optimal algorithm. This is a algorithm which can not be accurately implemented due to the fact that we rarely know how much time a process will need. However it provides a benchmark to measure other algorithms.

The optimal algorithm (also known as shortest job first or SJF) works like this. It will run the shortest job first from the process queue. Lets look at the wait times now.


So the average wait time is (0 + 3 + 9 + 16) / 4 = 7 ms and total time = 24ms. As you can see this algorithm has much better average wait time.

When OS are created the scheduling algorithm they use is very important. They must consider many things in order to make the scheduling work efficiently.