Round Robin Scheduling Algorithm in Operating system

Round Robin Scheduling algorithm with Example

The round-robin scheduling takes its name from the round-robin scheduling idea. This principle states that everyone will divide anything they possess equally among themselves.

Round Robin scheduling algorithm is used in a time-sharing system. It is generally used by those operating systems which has multiple clients so that they can make use of resources

Round robin scheduling is the preemptive scheduling algorithm. In this scheduling, every process gets executed cyclically or you can say that a particular time slice is allocated to each process to which we can say as time quantum.

Every process, which wants to execute itself, is present in the queue. CPU is assigned to the process for that time quantum. Now, if the process completed its execution in that quantum of time, then the process will get terminated, and if the process does not achieve its implementation, then the process will again be added to the ready queue, and the previous process will wait for its turn to complete its execution..

Example of round robin scheduling
In this example, we will take six processes P1, P2, P3, P4, P5 and P6 whose arrival and burst time are given in the table. The time quantum is four units.

Processes Arrival Time Burst Time
P1 0 5
P2 1 6
P3 2 3
P4 3 1
P5 4 5
P6 5 4

As the structures of ready queue and chart will change after every scheduling, so we have to maintain it in the algorithm again and again.

Ready Queue
Initially, in the starting, the process P1 will be executed for the given time quantum. So, there will be only one process P1 in the ready queue when we start the scheduling.

P1
5

chart

P1 will be executed for 4 units.

Ready Queue
Mid while, during the execution of process P1, some other processes like P2, P3,P4 and P5 arises for the execution in the ready queue. As we know P1 has not completed since its time is 5 and we have 4 units of time slice. So, 1 unit is still left. So it will be again added at the back in ready queue.

P2 P3 P4 P5 P1
6 3 1 5 1

chart
Now the chart will be like this.

Ready queue
When the process P2 is executing, another process P6 arrives in the ready queue. As we know that the process P2 has not terminated its execution as its 2 units of burst time is still left. So, for now we will add the process P2 in the ready queue at the back so that it can complete its execution.

P3 P4 P5 P1 P6 P2
3 1 5 1 4 2

CHART
Now, P3 will be executed for 3 units of time slice as its bursts time is 3 units.

Ready queue
Now the process P3 is completed in the time slice of 4 units. So, we will not add P3 in the ready queue and now we will execute the next process P4.

P4 P5 P6 P1 P2
1 5 1 4 2

Ready queue
The next process which is in the ready queue is P5 and it has 5 units of bursts time. Also, the process P4 gets completed or you can say that has terminated its execution as it has only 1 unit of bursts time.

P5 P6 P1 P2
5 1 4 2

  chart

Ready Queue
Now the process P5 has not completed its execution as 1 unit of burst time is left. So we add it in the ready queue in the back so that it can be further executed by the CPU.

P1 P6 P2 P5
1 4 2 1

  chart
Now the turn of the process P1 has come according to the ready queue. So, for now the process P1 will complete its execution. As we know it requires only 1 unit of bursts time, so it will get completed in this chance of execution.

Ready queue
As the process P1 also get completed. So, we will not add it into the ready queue. Now, overall only three processes P6, P2 and P5 are left.

P6 P2 P5
4 2 1

CHART
Now P6 has 4 units of bursts time. So it will get executed in 4 units of time slice

Ready queue
Since the process P6 is executed completely. So, we will not add it to the ready queue. Now only 2 processes left in the ready queue which are P2 and P5.

P2 P5
2 1

  CHART
Now P2 will be executed again and it requires only 2 units of bursts time. So now it will be completed.

Ready queue
Only process left in the ready queue is P5 which requires only 1 unit of bursts time. As we know our time slice is of 4 units. So it will get completed in the next burst.

P5
1

The process P5 will get executed until it get completed as it is the only process left in the ready queue.

Now we will calculate turn around time, completion time and average waiting time which is shown in the below table.
Turn around time= completion time- arrival time
Waiting time= turn around time – burst time

Average waiting time= (12+16+6+8+15+11)/6= 76/6 = 12.66 units

Advantages of round robin scheduling

  • It is simple.
    • It is easy to implement.
    • It deals with all process without any priority as no priority is given in this type of scheduling.
    • In this, all jobs get easily allocated to the CPU for their execution.
    • Here, no convoy effect or starvation occurs as it occurs in first come first serve scheduling algorithm.
    • Round robin scheduling algorithm does not depend upon burst time. So we can easily implement the round robin scheduling algorithm on the system.

Disadvantages of round robin scheduling

  • As we know that the time quantum is the main requirement of the round robin scheduling algorithm to execute processes. So, deciding a perfect time quantum for scheduling the processes is a very difficult and not an optimal task.
    • Higher the time quantum, higher the response time of the system.
    • Lower the time quantum, higher the context switching overhead.

Search within CuiTutorial

Scroll to Top