## DEV Community is a community of 789,560 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Anna

Posted on

# Scheduling Algorithms in Operating Systems - Part 5 - Highest Response Ratio next

#### You can skip the intro if you have been through the Part - 1 or Part - 2 or Part - 3 or Part - 4 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 Highest Response Ratio Next algorithm :

## Highest Response Ratio Next Algorithm:

In this, for execution, we select the process that has the highest response ratio.

Response Ratio =( Waiting Time + Service Time ) / Service time

Let us understand this using an example:

Here, process A is the only process to enter the processor and hence it starts executing. Meanwhile, B enters the queue.

Now, since B is the only process to enter the queue, it starts executing next.

Now comes the trickier part.

There are three processes β C, D, E in the queue. How do we decide which one to select out of these?

It's very easy! We calculate the response ratio for each of them using the formula mentioned earlier.

As you can see, C has the highest response ratio. Hence it will be executed next.

Now we have to choose between process D and E. Let us calculate the response ratio for these processes.

Since E has the highest response ratio, it is executed next.

Now the only process left is D. Hence, it will be executed finally.

Let us now calculate the average waiting time and turnaround time for this example:

This is how processes are scheduled using the Highest Response Ratio algorithm.

Here, the disadvantage is that extra calculation is required. Also, the service time has to be known and the waiting time has to be tracked.

Hope this helps you!

Have a nice day π!!

PS : This was the last part of the scheduling algorithms series. Hope all your questions were answered. Still if there's anything you need to ask or add to what I've posted please let me know in the comments.
Thanks!