Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Operating system time slicing in round robin scheduling
Round Robin (RR) is a CPU scheduling algorithm where each process is assigned a fixed time slot called a time slice (or time quantum). The CPU cycles through all ready processes in order, giving each one the time slice. If a process does not finish within its time slice, it is moved to the back of the queue and the next process gets the CPU.
This is one of the simplest and most widely used scheduling algorithms in operating systems, especially in time-sharing systems where fair CPU allocation is important.
How Round Robin Scheduling Works
The scheduler maintains a ready queue of processes. It picks the first process, runs it for the duration of the time slice (or until it finishes, whichever is shorter), then moves to the next process. If a process still has remaining burst time, it goes back to the end of the queue.
Example − Time Slice of 2 Units
Consider the following processes with their burst times −
| Process | Burst Time (units) |
|---|---|
| A | 4 |
| B | 1 |
| C | 8 |
| D | 1 |
With a time slice of 2 units, the CPU executes processes in the following order −
Step-by-Step Execution
| Time | Process | Runs For | Remaining Burst | Action |
|---|---|---|---|---|
| 0-2 | A | 2 | 2 | Back to queue |
| 2-3 | B | 1 | 0 | Completed |
| 3-5 | C | 2 | 6 | Back to queue |
| 5-6 | D | 1 | 0 | Completed |
| 6-8 | A | 2 | 0 | Completed |
| 8-10 | C | 2 | 4 | Back to queue |
| 10-12 | C | 2 | 2 | Back to queue |
| 12-14 | C | 2 | 0 | Completed |
Process A completes in 8 units (at time 8), B completes at time 3, C completes at time 14, and D completes at time 6. The total CPU utilization spans 14 units.
Calculating Average Times
| Process | Burst Time | Completion Time | Turnaround Time | Waiting Time |
|---|---|---|---|---|
| A | 4 | 8 | 8 | 4 |
| B | 1 | 3 | 3 | 2 |
| C | 8 | 14 | 14 | 6 |
| D | 1 | 6 | 6 | 5 |
Average Turnaround Time = (8 + 3 + 14 + 6) / 4 = 7.75 units
Average Waiting Time = (4 + 2 + 6 + 5) / 4 = 4.25 units
Conclusion
Round Robin scheduling uses time slicing to give each process a fair share of CPU time. It is simple, prevents starvation, and works well for time-sharing systems. The choice of time slice is critical ? too small increases context-switching overhead, while too large makes it behave like First Come First Served (FCFS).
