Longest Job First

LJF stands for Longest Job First. It is a CPU scheduling algorithm in which the CPU is assigned to the process having the largest burst time among all the available processes. This means that the process requiring the most CPU execution time is selected first, while processes with shorter burst times have to wait for their turn. LJF scheduling can be used in both preemptive and non-preemptive forms. In non-preemptive LJF, once a process gets the CPU, it continues its execution until it finishes or blocks. In the preemptive version, the CPU can be taken away from the currently running process if another process has a longer remaining execution time. The preemptive version of Longest Job First (LJF) is known as Longest Remaining Time First (LRTF).

In LJF, CPU is assign to the process having largest burst time among all the available processes.

How Does LJF Scheduling Work

In LJF scheduling, the operating system checks the burst time of all processes available in the ready queue and selects the process with the longest burst time for execution. If two or more processes have the same burst time, First Come First Serve (FCFS) is used to break the tie. This means that the process that arrived first in the ready queue gets the CPU first.

Example of SJF Scheduling

Suppose there are five processes P1, P2, P3, P4 and P5 having different burst time.

Explanation

Hence, there are different scheduling parameters explanation are as given.

Completion Time (CT)

  • Formula

CT = Arrival Time (AT) + Turnaround Time (TAT)

Turnaround Time (TAT)

  • Formula

TAT = Completion Time – Arrival Time

Waiting Time (WT)

  • Formula

WT = Turnaround Time – Burst Time

Advantages of LJF

  • LJF is easy to understand and implement.
  • Processes with longer burst times get the CPU first.
  • LJF gives the preference to processes that require more CPU execution time.

Disadvantages of LJF

  • Shorter processes may wait for a long time.
  • Short processes may suffer from the starvation.
  • In LJF, the short processes may have the poor response time.