Skip to content

Round-Robin (RR) Scheduling

Introduction

Round-Robin (RR) is a preemptive CPU scheduling algorithm designed for time-sharing systems. It assigns a fixed time quantum (or time slice) to each process, ensuring that all processes get a fair share of the CPU.

  • Each process executes for a fixed time quantum (TQ).
  • If a process doesn’t finish within TQ, it is moved to the end of the queue.
  • The CPU then executes the next process in the queue.
  • This cycle repeats until all processes are completed.

πŸ’‘ Round-Robin ensures fairness and prevents starvation, making it ideal for multitasking and time-sharing systems.


How Round-Robin Scheduling Works

  1. Processes are placed in a ready queue in the order they arrive.
  2. The CPU executes each process for a fixed time quantum (TQ).
  3. If a process completes within the time quantum, it is removed from the queue.
  4. If a process does not complete within the time quantum, it is sent to the back of the queue.
  5. The CPU then picks the next process in the queue.

Example of Round-Robin Scheduling

Given Processes and Time Quantum (TQ = 4 ms):

ProcessArrival Time (AT)Burst Time (BT)
P10 ms7 ms
P22 ms4 ms
P34 ms9 ms
P46 ms5 ms

Step-by-Step Execution (TQ = 4 ms)

  1. P1 starts execution (0 – 4 ms), but 3 ms remains.
  2. P2 starts execution (4 – 8 ms) and completes.
  3. P3 starts execution (8 – 12 ms), but 5 ms remains.
  4. P4 starts execution (12 – 16 ms), but 1 ms remains.
  5. P1 resumes execution (16 – 19 ms) and completes.
  6. P3 resumes execution (19 – 23 ms), but 1 ms remains.
  7. P4 resumes execution (23 – 24 ms) and completes.
  8. P3 resumes execution (24 – 25 ms) and completes.

Gantt Chart for Round-Robin Execution

| P1 | P1 | P1 | P1 | P2 | P2 | P2 | P2 | P3 | P3 | P3 | P3 | P4 | P4 | P4 | P4 | P1 | P1 | P1 | P3 | P3 | P3 | P3 | P4 | P3 |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

Calculation of Turnaround Time (TAT) & Waiting Time (WT):

ProcessArrival Time (AT)Burst Time (BT)Completion Time (CT)Turnaround Time (TAT) = CT – ATWaiting Time (WT) = TAT – BT
P10 ms7 ms19 ms19 ms12 ms
P22 ms4 ms8 ms6 ms2 ms
P34 ms9 ms25 ms21 ms12 ms
P46 ms5 ms24 ms18 ms13 ms

Advantages of Round-Robin Scheduling

βœ” Fair and simple β†’ Every process gets an equal CPU share.
βœ” Prevents starvation β†’ No process is left waiting indefinitely.
βœ” Suitable for time-sharing systems β†’ Ideal for interactive and multitasking environments.
βœ” Fast response time β†’ Ensures quick execution of short tasks.


Disadvantages of Round-Robin Scheduling

βœ– Context switching overhead β†’ Too many context switches slow down performance.
βœ– Time quantum selection is critical β†’

  • If TQ is too small β†’ High context switching overhead.
  • If TQ is too large β†’ RR behaves like FCFS, leading to poor response time.
    βœ– Not optimal for CPU-bound processes β†’ CPU-intensive tasks suffer because they get interrupted frequently.

When to Use Round-Robin Scheduling?

  • Best for interactive and time-sharing systems like operating systems, cloud computing, and multitasking environments.
  • Useful when all processes have similar burst times.
  • Not ideal for real-time systems where strict deadlines must be met.

Conclusion

Round-Robin (RR) is a widely used CPU scheduling algorithm because of its fairness and efficiency in time-sharing systems. It ensures that no process waits indefinitely and provides a balanced response time for all tasks. However, the selection of an appropriate time quantum is crucial for its effectiveness.