![]() |
VOOZH | about |
Round Robin is a CPU scheduling algorithm where each process is cyclically assigned a fixed time slot. It is the preemptive version of the First come First Serve CPU Scheduling algorithm.
This article focuses on implementing a Round Robin Scheduling Program where all processes have the same arrival time. In this scenario, all processes arrive at the same time which makes scheduling easier. You can focus on the main logic of dividing CPU time equally and managing the process queue.
Below are the key characteristics of the Round Robin Scheduling Algorithm when all processes share the same arrival time:
| Process | Completion Time | Turnaround Time (CT - AT) | Waiting Time (TAT - BT) |
|---|---|---|---|
| P1 | 17 | 17 | 10 |
| P2 | 13 | 13 | 9 |
| P3 | 20 | 20 | 11 |
- Create an array rem_bt[] to keep track of remaining burst time of processes. This array is initially a copy of bt[] (burst times array)
- Create another array wt[] to store waiting times of processes. Initialize this array as 0.
- Initialize time : t = 0
- Keep traversing all the processes while they are not done. Do following for i'th process if it is not done yet.
- If rem_bt[i] > quantum
- t = t + quantum
- rem_bt[i] -= quantum;
- Else // Last cycle for this process
- t = t + rem_bt[i];
- wt[i] = t - bt[i]
- rem_bt[i] = 0; // This process is over
Once we have waiting times, we can compute turn around time tat[i] of a process as sum of waiting and burst times, i.e., wt[i] + bt[i].
Below is implementation of above steps.
PN BT WT TAT 1 10 13 23 2 5 10 15 3 8 13 21 Average waiting time = 12 Average turn around time = 19.6667
Next Article to Read: Program for Round Robin Scheduling with Different Arrival Times for all Processes
In conclusion, Round Robin CPU scheduling is a fair and preemptive algorithm that allocates a fixed time quantum to each process, ensuring equal CPU access. It is simple to implement but can lead to higher context-switching overhead. While it promotes fairness and prevents starvation, it may result in longer waiting times and reduced throughput, depending on the time quantum. Effective program implementation allows for the calculation of key metrics like completion time, turnaround time, and waiting time, aiding in performance evaluation and optimization.