round robin rr - TarisMajor/5143-OpSystems GitHub Wiki

working-of-round-robin-scheduling-in-os

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

  1. 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.
  2. Cyclic Order: Processes are scheduled in a cyclic order, ensuring that all processes get an equal share of CPU time.
  3. Preemptive Nature: Round Robin is inherently preemptive, as processes are interrupted if they exceed their allotted time quantum.

Advantages of Round Robin Scheduling

  1. Fairness: Ensures that all processes receive an equal share of CPU time, preventing any single process from monopolizing the CPU.
  2. Improved Responsiveness: Suitable for interactive systems as it provides quick response times by frequently switching between processes.
  3. Simple Implementation: Relatively simple to implement and understand, making it a popular choice for many operating systems.

Disadvantages of Round Robin Scheduling

  1. Context Switching Overhead: Frequent context switching between processes can introduce significant overhead, impacting overall system performance.
  2. 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.
  3. 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

  1. Time-Sharing Systems: Ideal for time-sharing systems where multiple users share system resources and fair allocation of CPU time is essential.
  2. Interactive Systems: Suitable for interactive environments where quick response times and equal process treatment are crucial.
  3. 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:

  1. P1: Executes for 2 units (remaining 3 units)
  2. P2: Executes for 2 units (remaining 1 unit)
  3. P3: Executes for 2 units (remaining 6 units)
  4. P4: Executes for 2 units (remaining 4 units)
  5. P1: Executes for 2 units (remaining 1 unit)
  6. P2: Executes for 1 unit (completed)
  7. P3: Executes for 2 units (remaining 4 units)
  8. P4: Executes for 2 units (remaining 2 units)
  9. P1: Executes for 1 unit (completed)
  10. P3: Executes for 2 units (remaining 2 units)
  11. P4: Executes for 2 units (completed)
  12. 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.

Sources for Further Reading