Prerequisite – CPU Scheduling
Given n processes with their Arrival times and Burst times, the task is to find average waiting time and average turn around time using HRRN scheduling algorithm.
The name itself states that we need to find the response ratio of all available processes and select the one with the highest Response Ratio. A process once selected will run till completion.
Criteria – Response Ratio
Mode – Non-Preemptive
Response Ratio = (W + S)/S
Here, W is the waiting time of the process so far and S is the Burst time of the process.
Performance of HRRN –
- Shorter Processes are favoured.
- Aging without service increases ratio, longer jobs can get past shorter jobs.
Gantt Chart –
- At t = 0 we have only one process available, so A gets scheduled.
- Similarly at t = 3 we have only one process available, so B gets scheduled.
- Now at t = 9 we have 3 processes available, C, D and E. Since, C, D and E were available after 4, 6 and 8 units respectively. Therefore, waiting time for C, D and E are (9 – 4 =)5, (9 – 6 =)3, and (9 – 8 =)1 unit respectively.
- Using the formula given above we calculate the Response Ratios of C, D and E respectively as 2.25, 1.6 and 1.5.
- Clearly C has the highest Response Ratio and so it gets scheduled
- Next at t = 13 we have 2 jobs available D and E.
- Response Ratios of D and E are 2.4 and 3.5 respectively.
- So process E is selected next and process D is selected last.
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:
Name Arrival Time Burst Time Waiting Time TurnAround Time Normalized TT A 0 3 0 3 1.000000 B 2 6 1 7 1.166667 C 4 4 5 9 2.250000 E 8 2 5 7 3.500000 D 6 5 9 14 2.800000 Average waiting time:4.000000 Average Turn Around time:8.000000
This article is contributed by Siddhant Bajaj. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- HRRN Scheduling Full Form
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Program for FCFS CPU Scheduling | Set 1
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- CPU Scheduling in Operating Systems
- Operating Systems | CPU Scheduling | Question 1
- Operating Systems | CPU Scheduling | Question 2
- Program for Priority CPU Scheduling | Set 1
- Multilevel Queue (MLQ) CPU Scheduling
- Shortest Job First CPU Scheduling with predicted burst time
- Priority CPU Scheduling with different arrival time - Set 2
- Selfish Round Robin CPU Scheduling
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- Program for Preemptive Priority CPU Scheduling
- Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- Longest Remaining Time First (LRTF) CPU Scheduling Program
- Earliest Deadline First (EDF) CPU scheduling algorithm
- First Come, First Serve – CPU Scheduling | (Non-preemptive)
Improved By : Shivi_Aggarwal