Open In App

Round Robin Scheduling in Operating System

Last Updated : 24 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Round Robin Scheduling is a method used by operating systems to manage the execution time of multiple processes that are competing for CPU attention. It is called "round robin" because the system rotates through all the processes, allocating each of them a fixed time slice or "quantum", regardless of their priority.

The primary goal of this scheduling method is to ensure that all processes are given an equal opportunity to execute, promoting fairness among tasks.

Here's a simple breakdown:

  • Process Arrival: Processes enter the system and are placed in a queue.
  • Time Allocation: Each process is given a certain amount of CPU time, called a quantum.
  • Execution: The process uses the CPU for the allocated time.
  • Rotation: If the process completes within the time, it leaves the system. If not, it goes back to the end of the queue.
  • Repeat: The CPU continues to cycle through the queue until all processes are completed.
round_robinn
Round Robin Flow Chart

How Does It Work? - Imagine you're at a busy restaurant with a group of friends, and there's only one waiter. The waiter could spend a long time at one table, but instead, he choose to spend exactly one minute at each table before moving to the next. Similarly, in Round Robin Scheduling, the CPU spends a predetermined slice of time on each process. If a process hasn't finished its task by the time its slice is up, it's moved to the back of the queue, and the CPU moves on to the next process.

Advantages of Round Robin Scheduling

  • Fairness: Each process gets an equal share of the CPU.
  • Simplicity: The algorithm is straightforward and easy to implement.
  • Responsiveness: Round Robin can handle multiple processes without significant delays, making it ideal for time-sharing systems.

Disadvantages of Round Robin Scheduling:

  • Overhead: Switching between processes can lead to high overhead, especially if the quantum is too small.
  • Underutilization: If the quantum is too large, it can cause the CPU to feel unresponsive as it waits for a process to finish its time.

Example of Round Robin Scheduling Algorithm:

To understand the Round Robin Scheduling algorithm, let’s consider the following two scenarios:

Scenario 1: Processes with Same Arrival Time

Consider the following table of arrival time and burst time for three processes P1, P2 and P3 and given Time Quantum = 2 ms

ProcessBurst TimeArrival Time
 P1   4 ms0 ms
 P2 5 ms0 ms
 P3 3 ms0 ms

Step-by-Step Execution:

  1. Time 0-2 (P1): P1 runs for 2 ms (total time left: 2 ms).
  2. Time 2-4 (P2): P2 runs for 2 ms (total time left: 3 ms).
  3. Time 4-6 (P3): P3 runs for 2 ms (total time left: 1 ms).
  4. Time 6-8 (P1): P1 finishes its last 2 ms.
  5. Time 8-10 (P2): P2 runs for another 2 ms (total time left: 1 ms).
  6. Time 10-11 (P3): P3 finishes its last 1 ms.
  7. Time 11-12 (P2): P2 finishes its last 1 ms.
Gantt Chart:


Now, lets calculate average waiting time and turn around time:

  • Turnaround Time = Completion Time - Arrival Time
  • Waiting Time = Turnaround Time - Burst Time
ProcessesATBTCTTATWT
P10488-0 = 88-4 = 4
P2051212-0 = 1212-5 = 7
P3031111-0 = 1111-3 = 8
  • Average Turn around time = (8 + 12 + 11)/3 = 31/3 = 10.33 ms
  • Average waiting time = (4 + 7 + 8)/3 = 19/3 = 6.33 ms

Scenario 2: Processes with Different Arrival Times

Consider the following table of arrival time and burst time for three processes P1, P2 and P3 and given Time Quantum = 2

ProcessBurst Time (BT)Arrival Time (AT)
P15 ms0 ms
P22 ms4 ms
P34 ms5 ms
Step-by-Step Execution:
  • Time 0-2 (P1 Executes):
    • P1 starts execution as it arrives at 0 ms.
    • Runs for 2 ms; remaining burst time = 5 - 2 = 3 ms.
    • Ready Queue: [P1].
  • Time 2-4 (P1 Executes Again):
    • P1 continues execution since no other process has arrived yet.
    • Runs for 2 ms; remaining burst time = 3 - 2 = 1 ms.
    • P2 arrive at 4 ms.
    • Ready Queue: [P2, P1].
  • Time 4-6 (P2 Executes):
    • P2 starts execution as it arrives at 4 ms.
    • Runs for 2 ms; remaining burst time = 2 - 2 = 0 ms.
    • P3 arrive at 5ms
    • Ready Queue: [P1, P3].
  • Time 6-7 (P1 Executes):
    • P1 starts execution.
    • Runs for 1 ms; remaining burst time = 1 - 1 = 0 ms.
    • Ready Queue: [P3].
  • Time 7-9 (P3 Executes):
    • P3 starts execution.
    • Remaining burst time = 4 - 2 = 2 ms.
    • Ready Queue: [P3].
  • Time 9-11 (P3 Executes Again):
    • P3 resumes execution and runs for 2 ms and complete its execution
    • Remaining burst time = 2 - 2 = 0 ms.
    • Ready Queue: [].
Gantt Chart:
Now, lets calculate average waiting time and turn around time:
ProcessCompletion Time (CT)Turnaround Time (TAT = CT - AT)Waiting Time (WT = TAT - BT)
P17 ms7 ms2 ms
P26 ms2 ms0 ms
P311 ms6 ms2 ms
  • Average Turn around time =7+2+6/3��=15/3=5ms
  • Average waiting time = 2+0+2/3=1.33ms

Code Implementation:

1. Program for Round Robin Scheduling for the Same Arrival Time

2. Program for Round Robin Scheduling with Different Arrival Times


Next Article

Similar Reads