Round Robin is a CPU scheduling algorithm where each process is assigned a fixed time slot in a cyclic way.
- It is simple, easy to implement, and starvation-free as all processes get fair share of CPU.
- One of the most commonly used technique in CPU scheduling as a core.
- It is preemptive as processes are assigned CPU only for a fixed slice of time at most.
- The disadvantage of it is more overhead of context switching.
How to compute below times in Round Robin using a program?
- Completion Time: Time at which process completes its execution.
- Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = Completion Time – Arrival Time
- Waiting Time(W.T): Time Difference between turn around time and burst time.
Waiting Time = Turn Around Time – Burst Time
In this post, we have assumed arrival times as 0, so turn around and completion times are same.
The tricky part is to compute waiting times. Once waiting times are computed, turn around times can be quickly computed.
Steps to find waiting times of all processes:
1- 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) 2- Create another array wt to store waiting times of processes. Initialize this array as 0. 3- Initialize time : t = 0 4- Keep traversing the all processes while all processes are not done. Do following for i'th process if it is not done yet. a- If rem_bt[i] > quantum (i) t = t + quantum (ii) bt_rem[i] -= quantum; c- Else // Last cycle for this process (i) t = t + bt_rem[i]; (ii) wt[i] = t - bt[i] (ii) bt_rem[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.
Processes Burst time Waiting time Turn around time 1 10 13 23 2 5 10 15 3 8 13 21 Average waiting time = 12 Average turn around time = 19.6667
This article is contributed by Sahil Chhabra. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Round Robin Scheduling with different arrival times
- Operating System | Selfish Round Robin Scheduling
- Completion time of a given process in round robin
- Program for Priority Scheduling | Set 1
- Program for FCFS Scheduling | Set 1
- Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)
- Program for Shortest Job First (or SJF) scheduling | Set 1 (Non- preemptive)
- Program for Preemptive Priority CPU Scheduling
- Program for SSTF disk scheduling algorithm
- Program for FCFS Scheduling | Set 2 (Processes with different arrival times)
- CPU Scheduling | Longest Remaining Time First (LRTF) Program
- Disk Scheduling Algorithms
- Operating Systems | CPU Scheduling | Question 3
- Operating Systems | CPU Scheduling | Question 5
- Operating Systems | CPU Scheduling | Question 4