Operating System - Round Robin Scheduling Algorithm

Round Robin (RR) is one of the simplest and most widely used CPU scheduling algorithms in operating systems. It is designed especially for time-sharing systems. Each process is assigned a fixed time slice (called a time quantum) and is executed in a circular order.

Key Concepts

  • Preemptive algorithm: If a process doesn’t finish within its time quantum, it is preempted and placed at the back of the queue.

  • Time quantum: A small unit of time (e.g., 2ms, 4ms) allotted to each process.

  • Fairness: All processes get an equal share of CPU time in turns.

Steps of Round Robin Scheduling

  1. Add processes to the ready queue in order of arrival.

  2. Set a time quantum.

  3. Execute each process for at most the time quantum.

  4. If the process finishes in its quantum → Remove it.

  5. If not → Move it to the back of the queue.

  6. Repeat until all processes are completed.

Example

Given:

Process Arrival Time Burst Time
P1 0 5
P2 1 4
P3 2 6
Time Quantum = 2 units    

Let’s simulate the process:

Timeline (Gantt Chart):

Time →   0   2   4   6   8   10  11  13  15
         |P1 |P2 |P3 |P1 |P2 |P3 |P1 |P3 |  

Execution Order:

  • P1 runs from 0 to 2 (remaining: 3)

  • P2 runs from 2 to 4 (remaining: 2)

  • P3 runs from 4 to 6 (remaining: 4)

  • P1 runs from 6 to 8 (remaining: 1)

  • P2 runs from 8 to 10 (done)

  • P3 runs from 10 to 11 (remaining: 3)

  • P1 runs from 11 to 12 (done)

  • P3 runs from 12 to 14 (remaining: 1)

  • P3 runs from 14 to 15 (done)