# SRTF: Shortest Remaining Time First Scheduling Algorithm

This article is about the **SRTF Scheduling Algorithm in Operating System**. In this article, we are going to study about the **SRTF**, i.e. **Shortest Remaining Time First Scheduling Algorithm**. We will first define it briefly and will then illustrate it with the help of an example for understanding it better.

Submitted by Monika Sharma, on June 23, 2019

**SRTF**, Which Stands for **Shortest Remaining Time First** is a scheduling algorithm used in Operating Systems, which can also be called as the preemptive version of the SJF scheduling algorithm. The process which has the least processing time remaining is executed first. As it is a preemptive type of schedule, it is claimed to be better than SJF scheduling Algorithm.

Let's understand this with the help of an example. Suppose we have the following 3 processes with process ID's **P1**, **P2**, and **P3** and they arrive into the CPU in the following manner:

**Gant Chart:**

**Explanation:**

- At the 0
^{th}unit of the CPU, we have only process**P1**, so it gets executed for the 1-time unit. - At the 1
^{st}unit of the CPU, the Process**P2**also arrives. Now, the**P1**needs 7 more units more to be executed, and**P2**needs only 2 units. So,**P2**is executed by preempting**P1**. **P2**gets completed at time unit 3, and unit now no new process has arrived. So, after the completion of**P2**, again**P1**is sent for execution.- Now,
**P1**has been executed for one unit only, and we have an arrival of new process**P3**at time unit 4. Now, the**P1**needs 6-time units more and**P3**needs only 3-time units. So,**P3**is executed by preempting**P1**. **P1**gets completed at time unit 7, and after that, we have the arrival of no other process. So again,**P1**is sent for execution, and it gets completed at 13^{th}unit.

Total Turn Around Time = 13 + 2 + 3 = 18 milliseconds Average Turn Around Time= Total Turn Around Time / Total No. of Processes = 18 / 3 = 6 milliseconds Total Waiting Time = 5 + 0 + 0 = 5 milliseconds Average Waiting Time = Total Waiting Time / Total No. of Processes = 5 / 3 = 1.67 milliseconds

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.