round robin rr - TarisMajor/5143-OpSystems GitHub Wiki
Round Robin (RR) is a preemptive CPU scheduling algorithm widely used in time-sharing systems and interactive environments. It aims to ensure fairness and responsiveness by allocating a fixed time slice (quantum) to each process in the ready queue.
Key Characteristics of Round Robin Scheduling
- Time Quantum: Each process is given a fixed time slice, called a quantum, during which it can execute. If a process does not complete within its quantum, it is preempted and placed at the end of the ready queue.
- Cyclic Order: Processes are scheduled in a cyclic order, ensuring that all processes get an equal share of CPU time.
- Preemptive Nature: Round Robin is inherently preemptive, as processes are interrupted if they exceed their allotted time quantum.
Advantages of Round Robin Scheduling
- Fairness: Ensures that all processes receive an equal share of CPU time, preventing any single process from monopolizing the CPU.
- Improved Responsiveness: Suitable for interactive systems as it provides quick response times by frequently switching between processes.
- Simple Implementation: Relatively simple to implement and understand, making it a popular choice for many operating systems.
Disadvantages of Round Robin Scheduling
- Context Switching Overhead: Frequent context switching between processes can introduce significant overhead, impacting overall system performance.
- Quantum Size Sensitivity: The performance of Round Robin depends on the size of the time quantum. A small quantum can lead to excessive context switching, while a large quantum can reduce the algorithm's responsiveness.
- Inefficiency for Short Processes: Short processes may experience longer waiting times compared to other scheduling algorithms that prioritize shorter jobs.
Use Cases for Round Robin Scheduling
- Time-Sharing Systems: Ideal for time-sharing systems where multiple users share system resources and fair allocation of CPU time is essential.
- Interactive Systems: Suitable for interactive environments where quick response times and equal process treatment are crucial.
- Multitasking Systems: Commonly used in multitasking operating systems to ensure that all running processes get a fair share of CPU time.
Example of Round Robin Scheduling
Consider four processes with the following burst times and a time quantum of 2 units:
- Process P1: Burst Time = 5 units
- Process P2: Burst Time = 3 units
- Process P3: Burst Time = 8 units
- Process P4: Burst Time = 6 units
The Round Robin schedule with a quantum of 2 units would be:
- P1: Executes for 2 units (remaining 3 units)
- P2: Executes for 2 units (remaining 1 unit)
- P3: Executes for 2 units (remaining 6 units)
- P4: Executes for 2 units (remaining 4 units)
- P1: Executes for 2 units (remaining 1 unit)
- P2: Executes for 1 unit (completed)
- P3: Executes for 2 units (remaining 4 units)
- P4: Executes for 2 units (remaining 2 units)
- P1: Executes for 1 unit (completed)
- P3: Executes for 2 units (remaining 2 units)
- P4: Executes for 2 units (completed)
- P3: Executes for 2 units (completed)
The average waiting time can be calculated by summing the waiting times of all processes and dividing by the number of processes.