Scheduling Algorithms

In the diagram above, process P1, which came in first, will start running on the CPU. Since P1 can't finish running within only 4 ms of the time slice, it will be removed from the CPU in favor of the next processes in line.

A process can finish running in less than the given time slice if its burst time is less than 4 ms. This is exactly what each of processes P2 and P3 do.

The average waiting time in this schedule is (0 + (10 - 4) + 4 + 7) / 3 = 17 / 3 = 5.66 ms. We count (10 - 4) since we need to find how much time process P1 waited to get onto the CPU for the 2nd time, too.

The response time in this schedule is (0 + 4 + 7) / 3 = 11 / 3 = 3.66 ms.

[Remember that we define the response time to be the time it takes the process to get the CPU for the first time minus the arrival time. Since all 3 processes arrived at the same time (0th millisecond,) we don't subtract anything.]