Scheduling Algorithms in Operating Systems - Part 3 - Round Robin Algorithm
Published: 2021-12-07 12:22:46

---
title: Scheduling Algorithms in Operating Systems - Part 3 - Round Robin Algorithm
published: true
description: 
tags: 
cover_image: https://cdn-images-1.medium.com/max/2000/1*YFMjCPU7Ttl0xb1lmiUkVg.jpeg
---
#### You can skip the intro if you have been through the [**Part - 1**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-5g7a) or [**Part - 2**](https://dev.to/iamdigitalanna/scheduling-algorithms-in-operating-systems-part-2-shortest-job-first-sjf-4if3) of the series

Like humans, the operating system needs to plan its activities. These activities are the various processes that need to be executed by the OS. The OS needs to schedule all its processes properly to ensure that they get executed without any problems and in minimal time.

For this purpose, there are many scheduling algorithms like the **First Come First Serve** (FCFS) algorithm, **Shortest Job First** (SJF) algorithm, etc. We will be discussing these algorithms in detail but before that, we need to understand some terms.

 1. **Arrival Time**: The time at which the process arrives in the processor for execution.

 2. **Waiting Time**: The time for which a process has to wait before it starts executing. A process may have to wait if some other process is being executed (in a uniprocessor environment) or when the resources required by the process are not available, etc. It is calculated as :
>  *Waiting time = Completion Time- Arrival Time- Service Time*

3. **Service Time/ Burst time**: The time required by the process to complete its execution.

4. **Turnaround Time**: The interval between the time at which the process starts executing and the arrival time of the process. It is calculated using the formula:
>  *Turnaround Time = Service Time + Waiting Time*

Now, let us have a look at the Round Robin algorithm :

## Round robin algorithm :

In this method, every process is executed for a specific interval or time quantum and after the interval is over the next process to arrive starts executing for the same amount of time.

Let's take an example.
>  *Consider a time quantum of 4ms*

![](https://cdn-images-1.medium.com/max/2710/0*TLP0e6-hqum6yAuo.png)

A being the first process to arrive starts executing first.

![](https://cdn-images-1.medium.com/max/2060/0*Yvnx8bIp6mGEafyS.png)

Though the time quantum is 4ms, A needs 3ms, 1ms less than the time quantum. Hence, it gets completely executed 1ms earlier.

Now since B is the next process, it starts executing.

![](https://cdn-images-1.medium.com/max/2060/0*38DkdbnyloXa-1RT.png)

It executes for 4ms and then the execution stops. The next process i.e. C starts executing and B is put back into the waiting queue.

![](https://cdn-images-1.medium.com/max/2060/0*l5l3uK9qt6S2C4sg.png)

C process executes for 4ms and executes completely. Meanwhile, process E enters the queue.

Next, process D starts executing.

![](https://cdn-images-1.medium.com/max/2060/0*18iH4wpAzmcpOJIp.png)

Process D executes for 4ms whereas its required time was 5ms. Hence, it is added back into the queue and the next process to be executed is process B which will execute for 2ms.

![](https://cdn-images-1.medium.com/max/2460/0*FG3SiMEQQnCZd6Dq.png)

Next, process E will be executed for 2ms.

![](https://cdn-images-1.medium.com/max/2460/0*MrFoH8BhtY4Sqb15.png)

Now, the only process left in the queue is process D. Hence, it will get executed next for 1ms.

![](https://cdn-images-1.medium.com/max/2460/0*g03QxMVdJSLZ2QvU.png)

In this way, all processes are executed using the round-robin method.

Now let's have a look at the average waiting time and turnaround time.

![](https://cdn-images-1.medium.com/max/2710/0*GGCyuTyn0Pd99IUw.png)

Advantages :

An effective approach in time sharing or transaction processing time.

Disadvantages :

 1. Relative treatment of processor bound and I/O bound processes can cause poor performance.

 2. Inefficient use of I/O devices.

 3. Increase in variance of response time.

In the next post, let us have a look at the Priority Scheduling algorithm.


Hope this helps you!

Have a nice day 😊!!