round robin
round robin
Example 1
Assume there are 5 processes with process ID and burst time given below
P1 6
P2 5
P3 2
P4 3
P5 7
– Time quantum: 2
– Assume that all process arrives at 0.
Solution –
We can represent execution of above processes using GANTT chart as
shown below –
Page 1 sur 4
Round Robin Example Gantt Chart – 1
Explanation:
– First p1 process is picked from the ready queue and executes for 2 per
unit time (time slice = 2).
If arrival time is not available, it behaves like FCFS with time slice.
– After P2 is executed for 2 per unit time, P3 is picked up from the ready
queue. Since P3 burst
time is 2 so it will finish the process execution at once.
– Like P1 & P2 process execution, P4 and p5 will execute 2 time slices
and then again it will start
from P1 same as above.
Waiting time = Turn Around Time – Burst Time
P1 = 19 – 6 = 13
P2 = 20 – 5 = 15
P3 = 6 – 2 = 4
P4 = 15 – 3 = 12
P5 = 23 – 7 = 16
Example 2
Assume there are 6 processes with id, burst time and arrival time as
shown below –
P1 0 4
P2 1 5
P3 2 2
P4 3 1
P5 4 6
P6 6 3
Time quantum = 2
Now, we will calculate average waiting time, completion time, turn around
time for each processes’s execution.
Solution –
Execution of above processes can be represented using GANTT Chart as
shown below –
Page 2 sur 4
Gantt Chart Example – 2
Explanation –
At the arrival time = 0, CPU scheduler picks up the p1 process from the
ready queue and it will run per 2 unit of time according to given time
quantum.
At arrival time = 2, there are 3 processes available P1, P2 & P3. Executed
process will be placed at the tail of the ready queue. Scheduler will select
the next process from the ready queue. So, P2 will execute first. After the
execution of P2 process, P3 will be the next the process in the queue. So,
P3 will complete execution.
According to the context switch every executed process will be placed at
the tail of the ready queue and get a chance for execution again according
to each position.
Every process will follow the same procedure. It is good practice to make a
separate queue and place the process executed process at the tail of the
queue. So, it will be easy to understand the next process which is going to
be executed.
Completion time:
P1 = 8,
P2 = 18,
P3 = 6,
P4 = 9,
P5 = 21,
P6 = 19
Waiting time:
P1 = 8 – 4 = 4,
P2 = 17 – 5 = 12,
P3 = 4 – 2 = 2,
P4 = 6 – 1 = 5,
P5 = 17 – 6 = 11
Page 3 sur 4
value results in time starvation which may put many processes on hold.
So, time quantum should neither be large nor be small.
Page 4 sur 4