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 are arrived in the quantum time that make these scheduling fairly
- Round robin is cyclic in nature so starvation doesn’t occur
- Round robin is 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 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|
Quantum time is 3 this means each process is only executing for 3 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 quantum time has passed, check for any processes in Ready queue. If ready queue is empty continue current process. If queue not empty and current process is not complete, then add 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 process is complete and the ready queue is empty then 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 system.(completion time – arrival time).
- Waiting Time: total time the waiting for there complete execution.(turn around time – burst time ).
How to implement in 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:
name ctime wtime p1 22 12 p2 15 11 p3 16 11 p4 9 6 Average waiting time is 10.0 Average compilation time is 15.5 Sequence is like that ->p1->p2->p3->p4->p1->p2->p3->p1->p1
- Program for Round Robin scheduling | Set 1
- Selfish Round Robin CPU Scheduling
- Program for FCFS CPU Scheduling | Set 2 (Processes with different arrival times)
- Priority CPU Scheduling with different arrival time - Set 2
- Completion time of a given process in round robin
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Multilevel Queue (MLQ) CPU Scheduling
- Program for Priority CPU Scheduling | Set 1
- LOOK Disk Scheduling Algorithm
- Disk Scheduling Algorithms
- CPU Scheduling in Operating Systems
- C-LOOK Disk Scheduling Algorithm
- Program for FCFS CPU Scheduling | Set 1
- C-SCAN Disk Scheduling Algorithm
- FCFS Disk Scheduling Algorithms
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.