Operating System 355
complete within its time-slice, it has to give room for the next process, and it is placed at the end of the
short-term queue.
For our data set, we assume a time-slice of 5 milliseconds and solve the scheduling problem with
that. If we assume a very large time-slice, say 100 milliseconds, then there would not be any difference
between this and FCFS method, for the assumed data set of Table 11.1 . Interested reader may try and
observe it.
Figure 11.6 Round Robin (5 milliseconds time-slice)
So, we start our investigation with 5 milliseconds time-slice and remember that if any un nished pro-
cess is forced to leave the processor, it must be placed at the end of the queue, just like another new process.
To start with, process P1 enjoys two successive 5-millisecond time-slices as the next process, P2,
arrives at 10 milliseconds ( Figure 11.6 ). So, P1 leaves the CPU, occupying rst position of the queue as
P2 has now occupied the CPU for another 5 milliseconds. Note that total execution time of P1 and P2 are
16 and 12 milliseconds, respectively. However, during the execution of P2, P3 and P4 arrive and occupy
positions after P1 in the queue. Therefore, at the 15th millisecond, P2 releases the CPU and occupies
a position after P4 in the short-term queue. As P1 is rst in the short-term queue, it gets another 5 mil-
liseconds to use the processor.
After 20 milliseconds from starting, process P1 leaves the CPU and occupies the back seat of the
short-term queue behind P2. Note that P1 would need one more millisecond to complete its execution.
However, P3, in the now-leading position of the short-term queue, gets the chance for 5 milliseconds.
Thereafter, P4 occupies the CPU, for 2 milliseconds and next is the turn of P2. P2 gets another 5 milli-
seconds and leaves the CPU to make room of P1. Just after 1 millisecond, P1 completes its execution
and P2 gets its turn for completion of execution, which would now consume 2 milliseconds.
To calculate the average waiting time, we nd individual waiting time of all four processes, as fol-
lows (Figure 11.6 ):
Waiting time for process P1 = 17 milliseconds
Waiting time for process P2 = 13 milliseconds
Waiting time for process P3 = 8 milliseconds
Waiting time for process P4 = 12 milliseconds
Total waiting time = 50 milliseconds
Average waiting time = 50/4 = 12.5 milliseconds
11.3.8 Non–pre-emptive Priority
We shall now consider the fourth column of Table 11.1 in our scheduling experiments, which we have
ignored so far, as it was not necessary. This fourth column indicates the priority of the process, expressed
as an integer, and lesser is its value, higher would be the priority of the process. In pre-emptive priority
M11_GHOS1557_01_SE_C11.indd 355M11_GHOS1557_01_SE_C11.indd 355 4/29/11 5:22 PM4/29/11 5:22 PM