Round Robin Scheduling algorithm

CPU scheduling algorithm

Round Robin algorithm has time quantum. Time quantum is fixed for the execution of each process.

Criteria:

  • Time Quantum
  • Arrival Time

Decision Mode:

  • Preemptive: each process is allowed to run for a specified time duration, called its quantum. The process is allowed to run only for this time interval.
  • Non-Preemptive: for that, maintain the ready queue. First, come process executes till the time quantum value and likewise, processes are executes

Implementation:

  • This strategy can be implemented by using a circular FIFO queue

For Example:

In this, it has time quantum is 4 and context switch overhead is 1.

Process Arrival Time (A.T.) Burst Time (B.T.)
P0 0 10
P1 1 6
P2 3 2
P3 5 4

Gantt Chart:

Round Robin

Process Arrival Time Burst Time Completion Time Turnaround Time Waiting Time
P0 0 10 28 28 18
P1 1 6 25 24 18
P2 3 2 12 9 7
P3 5 4 22 17 13

Average Turnaround Time:(28+24+9+17)/4 = 19.5

Average Waiting Time: (18+18+7+13)/4 = 14

Advantages:

One of the oldest, simplest, fairest and most widely used algorithms.

Disadvantages:

Context switch overhead is there

Determination of time quantum is too critical. If it is too long it causes poor response for sort interactive processes.

Implementation of RR in C language:

#include<stdio.h>

int main()
{

int count,j,n,time,remain,flag=0,time_quantum;
int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10];
printf("Enter Total Process: ");
scanf("%d",&n);
remain=n;
for(count=0;count<n;count++)
{
printf("Enter Arrival Time and Burst Time for Process Process Number %d :",count+1);
scanf("%d",&at[count]);
scanf("%d",&bt[count]);
rt[count]=bt[count];
}
printf("Enter Time Quantum:\t");
scanf("%d",&time_quantum);
printf("\n\nProcess\t|Turnaround Time|Waiting Time\n\n");
for(time=0,count=0;remain!=0;)
{
if(rt[count]<=time_quantum && rt[count]>0)
{
time+=rt[count];
rt[count]=0;
flag=1;
}
else if(rt[count]>0)
{
rt[count]-=time_quantum;
time+=time_quantum;
}
if(rt[count]==0 && flag==1)
{
remain--;
printf("P[%d]\t|\t%d\t|\t%d\n",count+1,time-at[count],time-at[count]-bt[count]);
wait_time+=time-at[count]-bt[count];
turnaround_time+=time-at[count];
flag=0;
}
if(count==n-1)
count=0;
else if(at[count+1]<=time)
count++;
else
count=0;
}
printf("\nAverage Waiting Time= %f\n",wait_time*1.0/n);
printf("Avg Turnaround Time = %f",turnaround_time*1.0/n);

return 0;
}

In conclusion, Any query in RR Comment below in the comment box.
To learn more concept about RR go to 

https://www.geeksforgeeks.org/program-round-robin-scheduling-set-1/

For Android projects goto the ANDROID

Stay Connect with our app: – 

https://play.google.com/store/apps/details?id=com.edu.easyengineer

For Assignment Questions and Explanation of a theory topic visit:

http://mycandal.com/home/elementor-179/

About easyengineering 32 Articles
Easyengineering.in provides you to all subject and exam related materials online like GPSC, UPSC, IES, GATE, etc. As well as we provide daily job notification, some life-related books and other online courses which are useful too in your study.

Be the first to comment

Leave a Reply

Your email address will not be published.


*