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
- Processes are placed in a ready queue in the order they arrive.
- The CPU executes each process for a fixed time quantum (TQ).
- If a process completes within the time quantum, it is removed from the queue.
- If a process does not complete within the time quantum, it is sent to the back of the queue.
- The CPU then picks the next process in the queue.
Example of Round-Robin Scheduling
Given Processes and Time Quantum (TQ = 4 ms):
Process | Arrival Time (AT) | Burst Time (BT) |
---|---|---|
P1 | 0 ms | 7 ms |
P2 | 2 ms | 4 ms |
P3 | 4 ms | 9 ms |
P4 | 6 ms | 5 ms |
Step-by-Step Execution (TQ = 4 ms)
- P1 starts execution (0 – 4 ms), but 3 ms remains.
- P2 starts execution (4 – 8 ms) and completes.
- P3 starts execution (8 – 12 ms), but 5 ms remains.
- P4 starts execution (12 – 16 ms), but 1 ms remains.
- P1 resumes execution (16 – 19 ms) and completes.
- P3 resumes execution (19 – 23 ms), but 1 ms remains.
- P4 resumes execution (23 – 24 ms) and completes.
- 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):
Process | Arrival Time (AT) | Burst Time (BT) | Completion Time (CT) | Turnaround Time (TAT) = CT – AT | Waiting Time (WT) = TAT – BT |
---|---|---|---|---|---|
P1 | 0 ms | 7 ms | 19 ms | 19 ms | 12 ms |
P2 | 2 ms | 4 ms | 8 ms | 6 ms | 2 ms |
P3 | 4 ms | 9 ms | 25 ms | 21 ms | 12 ms |
P4 | 6 ms | 5 ms | 24 ms | 18 ms | 13 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.