Longest Remaining Time First (LRTF) or Preemptive Longest Job First CPU Scheduling Algorithm
Last Updated :
11 Jul, 2025
Longest Remaining Time First (LRTF) is a preemptive version of Longest Job First (LJF) scheduling algorithm. In this scheduling algorithm, we find the process with the maximum remaining time and then process it, i.e. check for the maximum remaining time after some interval of time(say 1 unit each) to check if another process having more Burst Time arrived up to that time.
Characteristics of Longest Remaining Time First (LRTF)
- Among all the processes waiting in a waiting queue, CPU is always assigned to the process having largest burst time.
- If two processes have the same burst time then the tie is broken using FCFS i.e. the process that arrived first is processed first.
- LJF CPU Scheduling can be of both preemptive and non-preemptive type.
Advantages of Longest Remaining Time First (LRTF)
- No other process can execute until the longest job or process executes completely.
- All the jobs or processes finishes at the same time approximately.
Disadvantages of Longest Remaining Time First (LRTF)
- This algorithm gives very high average waiting time and average turn-around time for a given set of processes.
- This may lead to convoy effect.
- It may happen that a short process may never get executed and the system keeps on executing the longer processes.
- It reduces the processing speed and thus reduces the efficiency and utilization of the system.
Longest Remaining Time First (LRTF) CPU Scheduling Algorithm
- Step-1: First, sort the processes in increasing order of their Arrival Time.
- Step-2: Choose the process having least arrival time but with most Burst Time.
- Step-3: Then process it for 1 unit. Check if any other process arrives upto that time of execution or not.
- Step-4: Repeat the above both steps until execute all the processes.
Examples to show working of Preemptive Longest Job First CPU Scheduling Algorithm:
Example-1: Consider the following table of arrival time and burst time for four processes P1, P2, P3 and P4.
|
P1 | 1 ms
| 2 ms
|
P2 | 2 ms
| 4 ms
|
P3 | 3 ms
| 6 ms
|
P4 | 4 ms
| 8 ms
|
The Longest Remaining Time First CPU Scheduling Algorithm will work on the basis of steps as mentioned below:
At time = 1,
- Available Process : P1. So, select P1 and execute 1 ms.
At time = 2,
- Available Process : P1, P2.
- So, select P2 and execute 1 ms (since B.T(P1) = 1 which is less than B.T(P2) = 4)
|
2-3ms | P1 | 1ms | P1 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 4ms | 3ms |
At time = 3,
- Available Process : P1, P2, P3.
- So, select P3 and execute 1 ms (since, B.T(P1) = 1 , B.T(P2) = 3 , B.T(P3) = 6).
|
3-4ms | P1 | 1ms | P1, P2 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 6ms | 5ms |
At time = 4,
- Available processes: P1, P2, P3, P4.
- So, select P4 (as burst time of P4 is largest) and execute 1 ms (since, B.T(P1) = 1 , B.T(P2) = 3 , B.T(P3) = 5, B.T(P4) = 8).
|
4-5ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 5ms | 5ms |
P4 | 4ms | 1ms | 8ms | 7ms |
At time = 5,
- Available processes: P1, P2, P3, P4,
- Process P4 will continue its execution as no other process has burst time larger than the Process P4
|
5-7ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 5ms | 5ms |
P4 | 4ms | 2ms | 7ms | 5ms |
At time = 7,
- The processes P3 and P4 have same remaining burst time,
- hence If two processes have the same burst time then the tie is broken using FCFS i.e. the process that arrived first is processed first.
- Therefore P3 will get executed for 1ms
|
7-8ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 5ms | 4ms |
P4 | 4ms | 0ms | 5ms | 5ms |
At time = 8,
- Available processes: P1, P2, P3, P4,
- Process P4 will again continue its execution as no other process has burst time larger than the Process P4
|
8-9ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 4ms | 4ms |
P4 | 4ms | 1ms | 5ms | 4ms |
At time = 9,
- Available processes: P1, P2, P3, P4,
- Process P3 continue its execution on the basis of FCFS rule.
|
9-10ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 4ms | 3ms |
P4 | 4ms | 0ms | 4ms | 4ms |
At time = 10,
- Available processes: P1, P2, P3, P4,
- Now again the burst time of P4 is largest, thus it will execute further.
|
10-11ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 3ms | 3ms |
P4 | 4ms | 1ms | 4ms | 3ms |
At time = 11,
- Available processes: P1, P2, P3, P4,
- Process P2 will continue its execution as the burst time of P2, P3, P4 is same
- Thus, in this case the further execution will be decided on the basis of FCFS i.e. the process that arrived first is processed first.
|
11-12ms | P1 | 1ms | P1, P3, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 3ms | 2ms |
P3 | 3ms | 0ms | 3ms | 3ms |
P4 | 4ms | 0ms | 3ms | 3ms |
At time = 12,
- Available processes: P1, P2, P3, P4,
- Process P3 continue its execution on the basis of above explanation.
|
12-13ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 2ms | 2ms |
P3 | 3ms | 1ms | 3ms | 2ms |
P4 | 4ms | 0ms | 3ms | 3ms |
At time = 13,
- Available processes: P1, P2, P3, P4,
- Now again the burst time of P4 is largest, thus it will execute further.
|
13-14ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 2ms | 2ms |
P3 | 3ms | 0ms | 2ms | 2ms |
P4 | 4ms | 1ms | 3ms | 2ms |
At time = 14,
- Available processes: P1, P2, P3, P4
- Now, the process P2 will again begin to execute first among all
|
14-15ms | P1 | 1ms | P1, P3, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 2ms | 1ms |
P3 | 3ms | 0ms | 2ms | 2ms |
P4 | 4ms | 0ms | 2ms | 2ms |
At time = 15,
- Available processes: P1, P2, P3, P4, now P3 will execute
|
15-16ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 1ms | 2ms | 1ms |
P4 | 4ms | 0ms | 2ms | 2ms |
At time = 16,
- Available processes: P1, P2, P3, P4,
- here, P4 will execute as it has the largest Burst time among all
|
16-17ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 1ms | 2ms | 1ms |
At time = 17,
- Available processes: P1, P2, P3, P4,
- Process P1 will execute here on the basis of above explanation
|
17-18ms | P1 | 1ms | P2, P3, P4 | 1ms | 1ms | 0ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 0ms | 1ms | 1ms |
At time = 18,
- Available processes: P2, P3, P4,
- Process P2 will execute.
|
18-19ms | P2 | 2ms | P3, P4 | 1ms | 1ms | 0ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 0ms | 1ms | 1ms |
At time = 19,
- Available processes: P3, P4,
- Process P3 will execute.
|
19-20ms | P3 | 3ms | P4 | 1ms | 1ms | 0ms |
P4 | 4ms | 0ms | 1ms | 1ms |
At time = 20,
- Process P4 will execute at the end.
At time = 22,
- Process P4 will finish its execution.
The overall execution of the processes will be as shown below
|
1-2ms | P1 | 1ms | | 1ms | 2ms | 1ms |
2-3ms | P1 | 1ms | P1 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 4ms | 3ms |
3-4ms | P1 | 1ms | P1, P2 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 6ms | 5ms |
4-5ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 5ms | 5ms |
P4 | 4ms | 1ms | 8ms | 7ms |
5-7ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 5ms | 5ms |
P4 | 4ms | 2ms | 7ms | 5ms |
7-8ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 5ms | 4ms |
P4 | 4ms | 0ms | 7ms | 5ms |
8-9ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 4ms | 4ms |
P4 | 4ms | 1ms | 5ms | 4ms |
9-10ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 1ms | 4ms | 3ms |
P4 | 4ms | 0ms | 4ms | 4ms |
10-11ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 3ms | 3ms |
P3 | 3ms | 0ms | 3ms | 3ms |
P4 | 4ms | 1ms | 4ms | 3ms |
11-12ms | P1 | 1ms | P1, P3, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 3ms | 2ms |
P3 | 3ms | 0ms | 3ms | 3ms |
P4 | 4ms | 0ms | 3ms | 3ms |
12-13ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 2ms | 2ms |
P3 | 3ms | 1ms | 3ms | 2ms |
P4 | 4ms | 0ms | 3ms | 3ms |
13-14ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 2ms | 2ms |
P3 | 3ms | 0ms | 2ms | 2ms |
P4 | 4ms | 1ms | 3ms | 2ms |
14-15ms | P1 | 1ms | P1, P3, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 1ms | 2ms | 1ms |
P3 | 3ms | 0ms | 2ms | 2ms |
P4 | 4ms | 0ms | 2ms | 2ms |
15-16ms | P1 | 1ms | P1, P2, P4 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 1ms | 2ms | 1ms |
P4 | 4ms | 0ms | 2ms | 2ms |
16-17ms | P1 | 1ms | P1, P2, P3 | 0ms | 1ms | 1ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 1ms | 2ms | 1ms |
17-18ms | P1 | 1ms | P2, P3, P4 | 1ms | 1ms | 0ms |
P2 | 2ms | 0ms | 1ms | 1ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 0ms | 1ms | 1ms |
18-19ms | P2 | 2ms | P3, P4 | 1ms | 1ms | 0ms |
P3 | 3ms | 0ms | 1ms | 1ms |
P4 | 4ms | 0ms | 1ms | 1ms |
19-20ms | P3 | 3ms | P4 | 1ms | 1ms | 0ms |
P4 | 4ms | 0ms | 1ms | 1ms |
20-21ms | P4 | 4ms | | 1ms | 1ms | 0ms |
Note: CPU will be idle for 0 to 1 unit time since there is no process available in the given interval.
Gantt chart will be as following below:

Since, completion time (C.T) can be directly determined by Gantt chart, and
Turn Around Time (TAT)
= (Completion Time) - (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) - (Burst Time)
Therefore, final table look like,

Total Turn Around Time = 68 ms
So, Average Turn Around Time = 68/4 = 17.00 ms
And, Total Waiting Time = 48 ms
So Average Waiting Time = 48/4 = 12.00 ms
Example-2: Consider the following table of arrival time and burst time for four processes P1, P2, P3,P4 and P5.
|
P1 | 0ms | 2ms |
P2 | 0ms | 3ms |
P3 | 2ms | 2ms |
P4 | 3ms | 5ms |
P5 | 4ms | 4ms |
Similarly example-1, Gantt chart for this example,

Since, completion time (CT) can be directly determined by Gantt chart, and
Turn Around Time (TAT)
= (Completion Time) - (Arrival Time)
Also, Waiting Time (WT)
= (Turn Around Time) - (Burst Time)
Therefore, final table look like,

Total Turn Around Time = 61 ms
So, Average Turn Around Time = 61/5 = 12.20 ms
And, Total Waiting Time = 45 ms
So, Average Waiting Time = 45/5 = 9.00 ms
Similar Reads
Operating System Tutorial An Operating System(OS) is a software that manages and handles hardware and software resources of a computing device. Responsible for managing and controlling all the activities and sharing of computer resources among different running applications.A low-level Software that includes all the basic fu
4 min read
OS Basics
Process & Threads
CPU Scheduling
Deadlock
Memory & Disk Management
Memory Management in Operating SystemMemory is a hardware component that stores data, instructions and information temporarily or permanently for processing. It consists of an array of bytes or words, each with a unique address. Memory holds both input data and program instructions needed for the CPU to execute tasks.Memory works close
7 min read
Fixed (or static) Partitioning in Operating SystemFixed partitioning, also known as static partitioning, is one of the earliest memory management techniques used in operating systems. In this method, the main memory is divided into a fixed number of partitions at system startup, and each partition is allocated to a process. These partitions remain
8 min read
Variable (or Dynamic) Partitioning in Operating SystemIn operating systems, Memory Management is the function responsible for allocating and managing a computerâs main memory. The memory Management function keeps track of the status of each memory location, either allocated or free to ensure effective and efficient use of Primary Memory. Below are Memo
4 min read
Paging in Operating SystemPaging is the process of moving parts of a program, called pages, from secondary storage (like a hard drive) into the main memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called pages.To keep track of where each page is stored in memory, the operating s
8 min read
Segmentation in Operating SystemA process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the exact sizes are called segments. Segmentation gives the user's view of the process which paging does not provide. Here the user's view is mapped to physical memory. Types of Segmentatio
4 min read
Segmentation in Operating SystemA process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the exact sizes are called segments. Segmentation gives the user's view of the process which paging does not provide. Here the user's view is mapped to physical memory. Types of Segmentatio
4 min read
Page Replacement Algorithms in Operating SystemsIn an operating system that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. Page replacement becomes necessary when a page fault occurs and no free page frames are in memory. in this article, we will discus
7 min read
File Systems in Operating SystemA computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data.File systems are a crucial part of any operating system
8 min read
File Systems in Operating SystemA computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data.File systems are a crucial part of any operating system
8 min read
Advanced OS
Practice