Round Robin (RR) Scheduling Examples

Round Robin (RR) scheduling is a CPU scheduling algorithm used by OS to manage multiple processes waiting for CPU time. Round Robin (RR) scheduling assigns a fixed time quantum to each process, also called a time slice. For any process, if the quantum period expires and the process still needs some more CPU time, then that process is appended to the ready queue for its next turn, and the CPU moves to the next process in the ready queue. Round Robin (RR) scheduling is cyclic in nature, so there is no starvation

The main aim of Round Robin (RR) scheduling is to provide fair and balanced CPU allocation to each process for its execution. It is the best case in a time-sharing and multitasking environment.

Important Note:

  • Round Robin (RR) scheduling is the combination of FCFS scheduling and preemptive scheduling mode.
  • Context switching occurs when the CPU stops executing one process and starts executing another process. This happens when the time quantum expires.

In this article, we will see various examples of Round Robin (RR) scheduling in OS

 

Round Robin (RR) Scheduling Example 01

Consider the following table where arrival time and burst time are given for the processes P1, P2, P3, and P4 with a given Time Quantum = 5 ms

Round Robin (RR) Scheduling Example- 1 - Given Table

Gantt Chart and Ready Queue Behaviour

At time 0, processes P1, P2, P3, and P4 arrive, and it is placed in the ready queue. CPU will get P1 now, and the Gantt chart will start

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 0

At time 5, P1 is preempted after a quantum period of 5ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P2

P1 is preempted and added to the end of the ready queue because its quantum period has expired after 5ms. Since P1 has a total burst time of 5 ms, it has already executed for 5 ms. Therefore, its remaining burst time is:

  • Remaining Busrt Time for P1 in Ready Queue = 21ms – 5ms = 16ms

Thus, P1 is placed back into the ready queue with a remaining burst time of 16ms.

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 5

At time 8,  P2 (having a burst time of 3ms) completes its execution at time 8ms. CPU now executes the next process in the ready queue, which is P3

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 8

At time 13, P3 is preempted after a quantum period of 5ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P4

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 13

At time 15, P4 (having burst time of 2ms) completes its execution at time 15ms. CPU now executes the next process in the ready queue, which is P1

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 15

At time 20, P1 is preempted after a quantum period of 5ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P3

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 20

At time 21, P3 (having a burst time of 1ms) completes its execution at time 21ms. CPU now executes the next process in the ready queue, which is P1

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 21

At time 26, P1 is preempted after a quantum period of 5ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P1

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 26

At time 31, P1 is preempted after a quantum period of 5ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P1

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 31

At time 32, P2 completes its execution at time 32ms. CPU now executes the next process in the ready queue; the ready queue is empty. That’s all

Round Robin (RR) Scheduling Example - 1 - Gantt chart and ready queue at time 32

All calculations of the given example of RR are given below

Round Robin (RR) Scheduling Example - 1 - TAT, WR, RT and all other calculations

Round Robin (RR) Scheduling Example 02

Consider the following table where arrival time and burst time are given for the processes P1, P2, P3, P4, and P5 with a given Time Quantum = 5 ms

Round Robin (RR) Scheduling Example- 2 - Given Table

Gantt Chart and Ready Queue Behaviour

At time 0, only process P1 arrives, and it is placed in the ready queue. CPU will get P1 now, and the Gantt chart will start

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 0

At time 0-3, P3 arrives, which is added to the end of the queue, and P1 is preempted after a quantum period of 3ms and added to the end of the ready queue. CPU now executes the next process in the ready queue, which is P3

P1 is preempted and added to the end of the ready queue because its quantum period has expired after 3ms. Since P1 has a total burst time of 8 ms, it has already executed for 3 ms. Therefore, its remaining burst time is:

  • Remaining Busrt Time for P1 in Ready Queue = 8ms – 3ms = 5ms

Thus, P1 is placed back into the ready queue with a remaining burst time of 5 ms.

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 3

At time 3-6, P2 and P4 arrive, which are added to the end of the queue, and P3 is preempted after a quantum period of 3ms and added to the end of the queue for its remaining burst time (7ms – 3ms = 4ms). CPU now executes the next process in the ready queue, which is P1

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 6

At time 6-9, P5 arrives, which is added to the end of the queue, and P1 is preempted after a quantum period of 3ms and added to the end of the queue for its remaining burst time (7ms – 3ms = 4ms). CPU now executes the next process in the ready queue, which is P2

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 9

At time 11, P2 (having a burst time of 2ms) completes its execution at time 11ms. CPU now executes the next process in the ready queue, which is P4

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 11

At time 14, P4 (having a burst time of 3ms) completes its execution at time 14ms. CPU now executes the next process in the ready queue, which is P3

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 14

At time 17,  P3 is preempted after a quantum period of 3ms and added to the end of the queue for its remaining burst time (4ms – 3ms = 1ms). CPU now executes the next process in the ready queue, which is P5

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 17

At time 20,  P5 is preempted after a quantum period of 3ms and added to the end of the queue for its remaining burst time (5ms – 3ms = 2ms). CPU now executes the next process in the ready queue, which is P1

 

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 20

At time 22, P1 (having a remaining burst time of 2ms) completes its execution at time 22ms. CPU now executes the next process in the ready queue, which is P3

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 22

At time 23, P3 (having a remaining burst time of 1ms) completes its execution at time 23ms. CPU now executes the next process in the ready queue, which is P5

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 23

At time 25, P5 (having a remaining burst time of 2ms) completes its execution at time 25ms. CPU now executes the next process in the ready queue, but ready queue is empty.

Round Robin (RR) Scheduling Example - 2 - Gantt chart and ready queue at time 25

All calculations of the given example of RR are given below

Round Robin (RR) Scheduling Example - 2 - TAT, WR, RT and all other calculations