๐น What is Round-Robin?
Round-Robin (RR) is a CPU scheduling algorithm where each process is given a fixed time slot (quantum) to run in a cyclic order.
Itโs simple, fair, and preemptive โ meaning a running process can be paused to let others run.
๐น Analogy:
Think of students sharing one laptop in a library.
Each gets 5 minutes. After 5 minutes, the next student gets a turn โ even if the first one isnโt done.
After everyone gets their chance, the first student gets the laptop again, and so on.
๐น How It Works (Step-by-Step):
-
All processes are placed in a queue (FIFO order).
-
The first process runs for a fixed time slice (say, 100ms).
-
If it finishes early โ it leaves the queue.
If not โ itโs paused and moved to the back of the queue. -
The next process gets its time slice.
-
This cycle repeats until all processes are completed.
๐น Characteristics:
| Feature | Description |
|---|---|
| Type | Preemptive |
| Fairness | All processes get equal CPU time (in turns) |
| Queue Used | Circular FIFO |
| Response Time | Good โ every process gets CPU quickly |
| Context Switches | Frequent (depends on time quantum) |
๐น Time Quantum (Important Concept)
-
A time quantum is the fixed CPU time given to each process.
-
Too small โ too many context switches โ overhead
-
Too large โ behaves like FCFS (First-Come-First-Serve)
Good system design = choosing a balanced time quantum.
๐น Example:
-
3 processes: P1, P2, P3
-
Time quantum = 4ms
-
Arrival Time: all at 0ms
-
Burst Times: P1=10ms, P2=4ms, P3=6ms
Execution order:
P1 โ P2 โ P3 โ P1 โ P3 โ P1Each gets 4ms before switching, continuing in a round-robin fashion until complete.
๐น Advantages:
-
Fair to all processes
-
Simple to implement
-
No starvation โ every process gets CPU time
-
Good for time-sharing systems
๐น Disadvantages:
-
Frequent context switching = CPU overhead
-
Performance depends heavily on quantum size