VOOZH about

URL: https://www.geeksforgeeks.org/operating-systems/program-for-hrrn-cpu-scheduling-algorithm/

⇱ Program for HRRN CPU Scheduling Algorithm - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program for HRRN CPU Scheduling Algorithm

Last Updated : 10 Jan, 2025

The Highest Response Ratio Next (HRRN) scheduling algorithm is a non-preemptive scheduling technique used in operating systems to manage the execution of processes. It is designed to improve upon simpler algorithms like First-Come-First-Serve (FCFS) and Shortest Job Next (SJN) by balancing both the waiting time and the burst time of processes.

The key idea behind HRRN is to calculate a response ratio for each process, which is a measure of how long a process has been waiting compared to the time it needs for execution. The formula for the response ratio is:

In HRRN, the process with the highest response ratio is selected for execution next. This approach gives priority to processes that have been waiting longer, but also considers the burst time, ensuring a fair balance between long-waiting and quick-execution processes.

HRRN aims to reduce both starvation (by giving priority to long-waiting processes) and the inefficiency of short-job priority (by balancing burst time with waiting time). It provides a more efficient and fair way of scheduling processes, making it suitable for systems where long and short tasks need to be managed together.

Implementation of HRRN Scheduling

  • Input the number of processes, their arrival times and burst times.
  • Sort them according to their arrival times.
  • At any given time calculate the response ratios and select the appropriate process to be scheduled.
  • Calculate the turn around time as completion time - arrival time.
  • Calculate the waiting time as turn around time - burst time.
  • Turn around time divided by the burst time gives the normalized turn around time.
  • Sum up the waiting and turn around times of all processes and divide by the number of processes to get the average waiting and turn around time.

Below is the implementation of above approach: 

Output:

PN	AT	BT	WT	TAT	NTT
A 0 3 0 3 1
B 2 6 1 7 1.16667
C 4 4 5 9 2.25
E 8 2 5 7 3.5
D 6 5 9 14 2.8
Average waiting time: 4
Average Turn Around time:8


Comment