Prerequisite: Round Robin Scheduling with arrival time as 0
Round robin scheduling algorithm is used to schedule process fairly each job a time slot or quantum and the interrupting the job if it is not completed by then the job come after the other job which is arrived in the quantum time that makes these scheduling fairly
- Round robin is cyclic in nature so starvation doesn’t occur
- Round robin is a variant of first come, first served scheduling
- No priority, special importance given to any process or task
- RR scheduling is also known as Time slicing scheduling
- Each process is served by CPU for a fixed time so priority is the same for each one
- Starvation does not occur because of its cyclic nature.
- Throughput depends on quantum time.
- If we want to give some process priority, we cannot.
|Process||Arrival Time||Burst Time||Completion time||Turn Around Time||Waiting time|
Quantum time is 2 this means each process is only executing for 2 units of time at a time.
How to compute these process requests:-
- Take the process which occurs first and start executing the process.(for quantum time only)
- Check if any other process request has arrived. If a process request arrives during the quantum time in which another process is executing, then add the new process to the Ready queue
- After the quantum time has passed, check for any processes in the Ready queue. If the ready queue is empty continue the current process. If the queue not empty and the current process is not complete, then add the current process to the end of the ready queue.
- Take the first process from the Ready queue and start executing it (same rules)
- Repeat all steps above from 2-5
- If the process is complete and the ready queue is empty then the task is complete
After all these we get the three times which are:
- Completion Time: the time taken for a process to complete.
- Turn Around Time: total time the process exists in the system. (completion time – arrival time).
- Waiting Time: total time the waiting for there complete execution. (turn around time – burst time ).
How to implement in a programming language
1. Create two arrays of burst time res_b and of arrival time res_a and copy the value of the b and a array for calculate the remaining time.(b is burst time, a arrival time). 2. Create an another array for wt to store waiting time. 3. Initialize Time : t=0; 4. Keep traversing the all process while all process are not done. Do following for i'th process if it is not done yet. a- if res_a[i]<= q (quantum time :- q) 1. if res_b[i]>q a. t=t+q b. res_b[i]-=q; c. a[i]+=q; 2. else res_b[i]<=q(for last to execute) a. t=t+b[i]; b. wt[i]=t-b[i]-a[i]; c.res_b[i]=0; b- else res_a[i]<q 1. Initialize j=0 to number of process if a[j]<a[i] (compare is there any other process come before these process) 1. if res_b[j]>q a. t=t+q b. res_b[j]-=q; c. a[j]+=q; 2. else res_b[j]<=q a. t=t+b[j]; b. wt[j]=t-b[j]-a[j]; c.res_b[j]=0; 2. now we executing the i'th process 1. if res_b[i]>q a. t=t+q b. res_b[i]-=q; c. a[i]+=q; 2. else res_b[i]<=q a. t=t+b[i]; b. wt[i]=t-b[i]-a[i]; c.res_b[i]=0;
Below is the implementation of the above approach:
Processes Arrival Time Burst time completion time Turn Around Time Waiting time 1 0 5 12 12 7 2 1 4 11 10 6 3 2 2 6 4 2 4 3 1 7 4 3 Average waiting time = 4.5 Average turn around time = 7.5
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Program for FCFS CPU Scheduling | Set 2 (Processes with different arrival times)
- Priority CPU Scheduling with different arrival time - Set 2
- Program for Round Robin scheduling | Set 1
- Selfish Round Robin CPU Scheduling
- Difference between First Come First Served (FCFS) and Round Robin (RR) Scheduling Algorithm
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between Longest Job First (LJF) and Round Robin (RR) scheduling algorithms
- Difference between Multi Level Queue (MLQ) Scheduling and Round Robin (RR) algorithms
- Relation in FCFS and Round Robin Scheduling Algorithm
- Relation between Preemptive Priority and Round Robin Scheduling Algorithm
- Calculate server loads using Round Robin Scheduling
- Priority to Round-robin scheduling with dynamic time quantum
- Difference between Arrival Time and Burst Time in CPU Scheduling
- Completion time of a given process in round robin
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Difference between Multi Level Queue Scheduling (MLQ) and Priority Scheduling
- Program for FCFS CPU Scheduling | Set 1
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.