DEV Community

Cover image for Scheduling Algorithms in Operating Systems - Part 3 - Round Robin Algorithm
Anna
Anna

Posted on

Scheduling Algorithms in Operating Systems - Part 3 - Round Robin Algorithm

You can skip the intro if you have been through the Part - 1 or Part - 2 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

    1. Service Time/ Burst time: The time required by the process to complete its execution.
    2. 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

A being the first process to arrive starts executing first.

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.

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.

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

Next, process D starts executing.

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.

Next, process E will be executed for 2ms.

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

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.

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 😊!!

Top comments (0)