Introduction to Round-Robin Scheduling
What is Round-Robin Scheduling?
This algorithm takes its name from the round-robin principle, which distributes something equally among all participants. This is the oldest, most straightforward scheduling algorithm used for multitasking. During round-robin scheduling, each ready task runs cyclically for a limited period. As a result of this algorithm, processes also run without starvation.
The Round Robin Algorithm Working Process
- A ready queue gets established for all processes.
- Each process' burst time gets compared to the CPU's time quantum.
- The Round Robin scheduling algorithm executes the process within the time quantum if the burst time is less than or equal to the time quantum.
- When a process' burst time exceeds a time quantum, the process gets executed until it reaches the time quantum (TQ).
- The time quantum expires, and the process checks to see if it has finished.
- As soon as the process is complete, it terminates. Otherwise, the process returns to the ready state.
Characteristics of Round Robin Scheduling
Round Robin Scheduling has the following essential characteristics:
- First, a Round Robin algorithm works on a preemptive basis.
- During time quantum/time slice, a fixed interval time allows moving to the following process on the CPU.
- In the queue, the preempted process appears at the end.
- It would be beneficial to have a minimum time slice for each task that needs to get completed. Nevertheless, it may differ from one OS to another.
- This algorithm responds to an event in real time within a given period.
Advantages
- Considering that it doesn't depend on the burst time, the system can use it.
- It is not affected by starvation or convoy effects.
- CPU resources are made available to all jobs on a fair basis.
Disadvantages
- The system's response time increases as the time quantum increases.
- Context switching is more expensive in systems with lower time quantum.
- It is challenging to determine a perfect time quantum in the system.
Important Terms
- Completion Time: refers to when a process is completed.
- Turn Around Time: represents the difference between completion and arrival times. To calculate the same, use this formula: Turn Around Time = Completion Time – Arrival Time.
- Waiting Time(W.T): It measures the time difference between turnaround time and burst time. As a result, Waiting Time = Turn Around Time – Burst Time
Code Sample
The following code demonstrates how Round Robin Scheduling Algorithm works in Java.
import java.util.Scanner; |