Longest Remaining Job First
Longest Remaining Job First is also called Longest Remaining Time First. In this method, the CPU is assigned to available process that has longest remaining execution time. If another process has a longer remaining time, the CPU can switch to that process. It means that if a new process arrives with a longer remaining time than the currently running process, the CPU can switch to the new process. It means that CPU execute or runs Longer remaining time first and than it execute the short remaining time first. It is a type of priority scheduling. If the both processes are a equal remaining time than CPU will select a process based on the tie-breaking rule or the rule of first come first serve (FCFS). According to the first come first serve (FCFS), the CPU will run or execute the process that arrived first in the ready queue.
| Note: In LRJF, the CPU always selects the process with the longest remaining execution time. |
Advantages of LRJF
- It gives the CPU to the process with the longest remaining time first.
- It is useful when long processes need more CPU time.
- It allows a new process to get the CPU, if it has a longer remaining time.
- It helps the long processes make progress earlier.
Disadvantages of LRJF
- Short processes may have to wait for a long time.
- It increases the waiting time of short processes.
- Starvation is possible for short processes.
- It is difficult to estimate remaining time.
Example 1: When Processes Have the Same Remaining Time
Suppose two processes have the same remaining execution time.

Explanation
In this CPU Scheduling Parameters table example show that process and the remaining time. Both P1 and P2 have the same remaining execution time. If we use FCFS as the tie-breaking rule, the CPU will execute the process that arrived first.
Example: If P1 arrived first than the CPU will select the P1, according to the FCFS.
Example 2: When Processes Have the Different Remaining Times
Suppose two processes have the different remaining execution time.

Explanation
P1 has 5 units remaining, while P2 has 7 units remaining. The CPU will select the P2 because it has the longest remaining execution time.