Table of Contents
Round Robin Scheduling Algorithm with Example
In this tutorial we will explain the concept of Round Robin Scheduling Algorithm in operating system with an example.
Questions on Round robin scheduling in os are generally asked in GATE and UGC NET Exam.
Computer Science students and GATE Aspirants are suggested to read the tutorial completely.
Frequently Asked Questions
Some frequently asked questions on round robin scheduling algorithm in os are as follow –
- What is time quantum ?
- What is round robin scheduling in OS ?
- Why round robin scheduling is best ?
- Which type of operating system use round robin Scheduling algorithm ?
- Is round robin Scheduling is Preemptive ?
- What are advantages of using round robin scheduling algorithm ?
- What are disadvantage of round robin scheduling algorithm ?
After reading this tutorial student can easily answer the above questions and also can solve the problem’s based on round robin scheduling in os.
Let’s start with introduction of Round Robin CPU Scheduling Algorithm.
What is Round Robin Scheduling in OS ?
- Round Robin is thе Prееmptivе Procеss Schеduling Algorithm.
- Еach procеss is providеd a fix timе to еxеcutе and this time is known as callеd time quantum.
- Oncе a procеss is еxеcutеd for givеn timе pеriod. Procеss is prееmptеd and othеr procеss еxеcutеs for givеn timе quantum.
- Contеxt switching is usеd to savе statеs of prееmptеd procеssеs
- Round robin Scheduling is used in Time Sharing Operating System.
- Round Robin Scheduling is a real time algorithm which respond to an event in fixed time limit.
Flow chart for the working of Round Robin Scheduling in OS is given below
Note – Important Point to rammer about round robin scheduling is that when a process is preempted after time slice expires then preempted process is added to the end of ready queue.
Advantages of Round Robin Scheduling
- Round Robin Scheduling in OS gives the best performance in terms of average response time.
- Round Robin is best suited for time sharing system, client server architecture and
interactive system.
Disadvantages of Round Robin Scheduling
- Round Robin Scheduling leads to starvation for processes with larger burst time as they have to repeat the cycle many times.
- Round Robin Scheduling performance heavily depends on time quantum.
- Priorities can not be set for the processes.
Example of Round Robin Scheduling
Consider a System with 5 process with their arrival time and burst time as shown in following table. If the Time Quantum is of 2 ms then calculate the Average Waiting time and average turnaround time.
When we will prepare the Gantt Chart for the above process using round robin scheduling then it will as shown in above figure.
Step wise step Explanation of Round Robin Example
Now understand this step wise step explanation of round robin scheduling algorithm example.
Step1 – At time t= 0 only P1 is in ready queue so CPU will start to execute the Process P1 and execute it till Time Quantum 2 at time t=2 P1 will be preempted and added to the end of ready queue.
Step 2- At time t=2 there are 3 processes in ready queue in order P2 ( arrived at t=1) , P3 and Process P1( After Preemption added at end of ready queue).
Since Process P2 is at the front of ready queue so CPU will fetch P2 and execute for the time quantum value 2. So at T=4 Process P2 will be preempted.
Step3 – At time t=4, there will 5 processes in the ready queue in order P3,P1,P4,P5 and P2 ( after Preemption added to end of ready queue).
Since Process P3 is at the Front of Ready queue so CPU will execute P3 up to 1 ms because burst time of process is 1 ms which is less than the time quantum. So at time t=5 process P3 will complete.
Step 4- At time t=5 there will be 4 process in ready queue in order P1, P4, P5 and P2. So at time t=5 CPU will execute P1 till Time t = 7, at t= 7 p1 is preempted and added at the end of ready queue.
Step 5 – At Time t=7, four process will be there in ready queue in order P4, P5, P2 and P1. CPU will fetch P4 and since Burst time of P4 is 2 ms so P4 will complete with in time quantum it means P4 will complete at time t=9.
Step 6-At Time t=9, there will be 3 processes in ready queue in order P5, P2 and P1.CPU will fetch P5 execute it till time quantum 2 it means at t=11, process P5 will be preempted and added to the end of ready queue.
Step 7- AT t= 11 there will be 3 process in ready queue in order P2, P1, P5. CPU will fetch to P2 and execute till tim1 =12 since Remaining burst time of P2 was 1. At time t=12 there P2 will complete.
Step 8 – At time t= 12 only 2 process are there in ready in order P1, P5. CPU will fetch P1 and execute till time =13 since Remaining burst time of P1 was 1. At time t=11 there P1 will complete.
Step 9 – At time t= 13 only 2 process are there in ready queue Which is P5 so CPU will fetch it and execute it till time t=14 since Remaining burst time of P5 was 1. P5 will be completed at time t=14
Since we know that
Waiting Time = Completion time-Arrival time-Burst Time
Average Waiting Time = ( Total Waiting Time)/Number of Processes
Turn Around Time = Completion time – Arrival time
Average Turn Around Time = ( Total Turn Around Time)/Number of Process
Waiting time and Turnaround time of each process is as shown in following table.
Average Waiting time = ( 13+11+3+6+10)/5= 8.6 ms
Average turnaround time =(8+8+2+4+7)/5= 5.8 ms
Note – If you want to avoid mistake while solving the round robin cpu scheduling based problem then always maintain a queue for process which represents the process status of removing from queue and submitting in queue with respect to time.
Conclusion and Summary
- In this tutorial we have explained the round robin cpu scheduling in os with an example.
- Advantages and disadvantages of round robin CPU scheduling is also explained in this post.
- After reading this tutorial student can solve the round robin problems.
- I hope this tutorial will be helpful to you.