# Round Robin Scheduling algorithm

## CPU scheduling algorithm

The Round Robin Scheduling algorithm has time quantum. Time quantum is fixed for the execution of each process. this name includes the equal share of something into their turns.

## Characteristics of Round Robin Scheduling Algorithm

1. It is a pre-emptive algorithm in nature that is added to the end of the queue.
2. It is a hybrid model that is clock-driven.
3. It is used more in traditional OS (Operating system).
4. It is the very easiest and oldest algorithm.
5. It is the real time-based algorithm that responds to the event in a specific time limit.
6. The slice is varying from OS to OS and it should be minimum, which is assigned to a specific time.

• Time Quantum
• Arrival Time

## Round Robin 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

## Round Robin Implementation

• This strategy can be implemented by using a circular FIFO queue in the Round Robin Scheduling algorithm.

## 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 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

1. One of the oldest, simplest, fairest, and most widely used algorithms.
2. It deals with all processes without any priority and worry.
3. That’s performance is very good than another algorithm in terms of average responding time.
4. It does not face any difficulty in the convoy effect.
5. CPU allocation is distributed by the algorithm fairly.
6. If one process is specified in the set of the time period, the process is preempted, and another process will start within that time period.
7. this scheduling algorithm does not depend on the burst time, which is helpful to easily implement to any operating system.

1. Context switch overhead is there.
2. The time spends by context switching is more.
3. It decreases comprehension.
4. When higher context switching is implemented we get lower quantum results.
5. The priorities can’t be set for the processes.
6. Difficult to find the correct timing of quantum in the algorithm.
7. The performance heavily depends on the quantum.
8. It doesn’t give special priority to the important task.

## Worst Case Latency

This term is used for the maximum time taken for the execution of all task mentions.

• dt –> It denotes the detection time in which task is brought to the list.
• et –> It denotes the task execution time.

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,bt,rt;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++;elsecount=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.

## Summary

1. The Robin Scheduling Algorithm is a pre-emptive algorithm and it is used mostly in old OS
2. It is very easy to understand and we can easily execute.

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

For Android projects goto the ANDROID

Stay Connect with our app

` `