In previous post, we have discussed Set 1 of SJF i.e. non-preemptive. In this post we will discuss the preemptive version of SJF known as Shortest Remaining Time First (SRTF).
Shortest Remaining Time First (SRTF) scheduling
In the Shortest Remaining Time First (SRTF) scheduling algorithm, the process with the smallest amount of time remaining until completion is selected to execute. Since the currently executing process is the one with the shortest amount of time remaining by definition, and since that time should only reduce as execution progresses, processes will always run until they complete or a new process is added that requires a smaller amount of time.
Shortest Remaining Time First (Preemptive SJF): Example
P1 waiting time: 4-2 = 2
P2 waiting time: 0
The average waiting time(AWT): (0 + 2) / 2 = 1
1- Short processes are handled very quickly.
2- The system also requires very little overhead since it only makes a decision when a process completes or a new process is added.
3- When a new process is added the algorithm only needs to compare the currently executing process with the new process, ignoring all other processes currently waiting to execute.
1- Like shortest job first, it has the potential for process starvation.
2- Long processes may be held off indefinitely if short processes are continually added.
1- Traverse until all process gets completely executed. a) Find process with minimum remaining time at every single time lap. b) Reduce its time by 1. c) Check if its remaining time becomes 0 d) Increment the counter of process completion. e) Completion time of current process = current_time +1; e) Calculate waiting time for each completed process. wt[i]= Completion time - arrival_time-burst_time f)Increment time lap by one. 2- Find turnaround time (waiting_time+burst_time).
Processes Burst time Waiting time Turn around time 1 6 3 9 2 8 16 24 3 7 8 15 4 3 0 3 Average waiting time = 6.75 Average turn around time = 12.75
This article is contributed by Sahil Chhabra. 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 DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- Difference between Preemptive and Non-preemptive CPU scheduling algorithms
- Preemptive and Non-Preemptive Scheduling
- Clairvoyant Shortest Job first (SJF)
- Implementation of Non-Preemptive Shortest Job First using Priority Queue
- First Come, First Serve – CPU Scheduling | (Non-preemptive)
- Shortest Job First CPU Scheduling with predicted burst time
- Difference between Multi Level Queue Scheduling (MLQ) and Shortest Job First
- Difference between First Come First Served (FCFS) and Longest Job First (LJF) CPU scheduling algorithms
- Program for Preemptive Priority CPU Scheduling
- Difference between SJF and LJF CPU scheduling algorithms
- Difference between FCFS and SJF CPU scheduling algorithms
- Difference between SJF and SRJF CPU scheduling algorithms
- Relation in FCFS and Preemptive Priority Scheduling Algorithm
- Relation between Preemptive Priority and Round Robin Scheduling Algorithm
- Difference between Longest Job First (LJF) and Round Robin (RR) scheduling algorithms