Search anything:

Round Robin Scheduling Algorithm

Binary Tree book by OpenGenus

Open-Source Internship opportunity by OpenGenus for programmers. Apply now.

Reading time: 25 minutes | Coding time: 10 minutes

Round Robin Scheduling Algorithm is one of the simplest scheduling algorithm used in various operating systems for process scheduling and networks. The key idea is to allocate CPU to all processes in the same order for the same amount of time.

It is also a preemptive scheduling algorithm famous for CPU Scheduling and used in various Operating Systems. It is better than other approaches like Shortest Job First algorithms considering that there is a guarantee that all processes will be completed at the cost of overall performance but it is better than brute force approach.

In fact, Round Robin scheduling algorithm is one of the first algorithms to provide a real time computing experience.

Algorithm Explanation

The aim of this algorithm is to determine or schedule the order of execution of the processes. Now first each process is given with a fixed amount of time period known as quanta , this time quantum remains fixed throughout the process.

Each process can only be executed for one quanta at a time if the process manages to complete the execution within this time then it is terminated else it is preempted and has to wait for it's turn in a circular order to execute again, here context switching is used to save states of the preempted processes.

Advantages of Round Robin Algorithm

  • Because of the fixed quantum time each and every process has the same priority.
  • No stagnation or starvation of processes occurs, no process gets left behind.
  • There will be a improvement in average response time of the processes.
  • CPU is best utilized, no need of any extra resources.
  • Threads having same priority are scheduled perfectly with Round Robin as CPU is equally shared between all processes.

Disadvantages of Round Robin Algorithm

  • Higher average waiting time because every process has to wait until it's turn.
  • The length of quantum time has a large effect on the waiting time, too less will cause more time waste in switching through the processes than executing them effectively.
  • Low Throughput, means decreased rate of output or completion as a process is not completely executed at a time.
  • Lack of priority might be a problem in cases with processes which require immediate attention.

Example of Round Robin Algorithm

Consider the following example with five processes each one with varied execution time and a quantum time of 100 ms

Process Name Arrival Time Execution Time
P0 0 250
P1 50 170
P2 130 75
P3 190 100
P4 210 130
P5 350 50
  1. First, each and every process gets a quantum time of 100 ms.
  2. Note that the processes P2 and P5 which have an execution time less than the quantum time hence once their execution is complete they are terminated and the next process takes over.
  3. Other process which have execution time more than 100 ms will take multiple turns to complete their execution process.

Now the scheduling will be as follows :


Program of Round Robin Algorithm in C++

Following is the C++ implementation of Round Robin scheduling algorihm (go through it carefully):

// Part of OpenGenus IQ
void main()
    // p -> process
    char p[10][5];
    // et -> execution time for current turn
    // wt -> waiting time
    // pt -> processing time (taken as input)
    int et[10], wt[10], timer=3, count, pt[10], rt;
    int i, j, totwt=0, t, n=5, found=0, m;
    float avgwt;
    // Read the process name and processing time
        printf("enter the process name : ");
        printf("enter the processing time : ");
    wt[0] = 0;
    // Scheduling starts
    } while(i<n);

    // Display the Result
        printf("\nProcess Name\tProcessing Time\tWaiting Time");
    printf("\nTotal waiting time %d\n",totwt);
    printf("Average waiting time %f",avgwt);



Enter the process name : A
Enter the processing time : 4
Enter the process name : B
Enter the processing time : 3
Enter the process name : C
Enter the processing time : 2
Enter the process name : D
Enter the processing time : 5
Enter the process name : E
Enter the processing time : 1


Process Name Processing Time Waiting Time
A 4 9
B 3 3
C 2 6
D 5 10
E 1 11

Total waiting time : 39
Average waiting time : 7.8000


Round Robin Scheduling algorithm may seem to be a simple algorithm but it is mathematically proven to be a decent approach. Compare this with a greedy algorithm like Shortest Job First Scheduling.

In such greedy algorithms, there may be processes which may never complete in the cost of immediate better performance. In case of Round Robin Scheduling, though the overall performance may be worst but there is a guarantee that everything will be completed.

This is an important approach as it shows how simple algorithms can be designed. Think of this algorithmic approach in other domains and you will get to understand deeper Computer Science concepts.

With this, you have the complete knowledge of Round Robin Scheduling algorithm. Enjoy.

Round Robin Scheduling Algorithm
Share this