Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Notes  >  Operating System  >  Longest Job First (LJF) CPU Scheduling Algorithm

Longest Job First (LJF) CPU Scheduling Algorithm

Introduction

Longest Job First (LJF) is a non-preemptive scheduling algorithm. This algorithm is based on the burst time of the processes. The processes are put into the ready queue based on their burst times i.e., in descending order of the burst times. As the name suggests this algorithm is based on the fact that the process with the largest burst time is processed first. The burst time of only those processes is considered that have arrived in the system until that time. Its preemptive version is called Longest Remaining Time First (LRTF) algorithm. 

Prerequisite: Process Management | CPU Scheduling 

Introduction

Characteristics of Longest Job First(Non-Preemptive)

  • Among all the processes waiting in a waiting queue, the CPU is always assigned to the process having the 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 types.

Advantages of Longest Job First(LJF)

  • No other process can execute until the longest job or process executes completely.
  • All the jobs or processes finish at the same time approximately.

Disadvantages of Longest Job First CPU Scheduling Algorithm

  • This algorithm gives a very high average waiting time and average turn-around time for a given set of processes.
  • This may lead to a 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 Job First CPU Scheduling Algorithm

  • Step-1: First, sort the processes in increasing order of their Arrival Time. 
  • Step 2: Choose the process having the highest Burst Time among all the processes that have arrived till that time. 
  • Step 3: Then process it for its burst time. Check if any other process arrives until this process completes execution. 
  • Step 4: Repeat the above three steps until all the processes are executed. 

Let us consider the following examples. 
Example 1: Consider the following table of arrival time and burst time for four processes P1, P2, P3 and P4.  
Longest Job First CPU Scheduling Algorithm

The Longest Job First CPU Scheduling Algorithm will work on the basis of steps as mentioned below:
At time = 1, Available Process : P1. So, select P1 and start executing.
Longest Job First CPU Scheduling Algorithm

At time = 2

  • Process P2 arrives 
  • As P1 is executing thus, Process P2 will wait in the waiting queue.

Longest Job First CPU Scheduling Algorithm

At time = 3

  • P1 gets executed, and process P3 arrives
  • Available Process: P2, P3. So, select P3 and execute 6 ms (since B.T(P3)=6 which is higher than B.T(P2) = 4)
    Longest Job First CPU Scheduling Algorithm

At time = 4,

  • Process P4 arrives,
  • As P3 is executing thus, Process P4 will wait in the waiting queue
    Longest Job First CPU Scheduling Algorithm

At time = 5,

  • Process P3 is executing and P2 and P4 are in the waiting Table.
    Longest Job First CPU Scheduling Algorithm

At time = 9

  • Process P3 completes its execution, 
  • Available Process : P2, P4. So, select P4 and execute 8 ms (since, B.T(P4) = 8, B.T(P2) = 4)
    Longest Job First CPU Scheduling Algorithm

At time = 17,

  • Finally execute the process P2 for 4 ms.
    Longest Job First CPU Scheduling Algorithm

At time = 21,

  • Process P2 will finish its execution.
  • The overall execution of the processes will be as shown below:
    Longest Job First CPU Scheduling Algorithm

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:
Longest Job First CPU Scheduling Algorithm

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

P.NoArrival Time (AT)Completion Time (CT)Burst Time (BT)Turn Around Time (TAT)Waiting Time (WT)
P11 ms3 ms2 ms2 ms0 ms
P22 ms21 ms4 ms19 ms15 ms
P33 ms9 ms6 ms6 ms0 ms
P44 ms17 ms8 ms13 ms5 ms

Output :  

  • Total Turn Around Time = 2 + 19 + 6 + 13 = 40 ms

  • Average Turn Around Time = 40 ÷ 4 = 10 ms

  • Total Waiting Time = 0 + 15 + 0 + 5 = 20 ms

  • Average Waiting Time = 20 ÷ 4 = 5 ms

The document Longest Job First (LJF) CPU Scheduling Algorithm is a part of the Computer Science Engineering (CSE) Course Operating System.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)

FAQs on Longest Job First (LJF) CPU Scheduling Algorithm

1. What is the Longest Job First (LJF) CPU Scheduling Algorithm?
Ans. The Longest Job First (LJF) CPU Scheduling Algorithm is a non-preemptive scheduling method that prioritizes processes based on their execution time. In this algorithm, the process with the longest estimated run time is selected to execute next. The rationale behind LJF is that longer tasks get completed first, potentially reducing the total waiting time for shorter tasks in the system.
2. What are the advantages of using the LJF scheduling algorithm?
Ans. The advantages of the LJF scheduling algorithm include improved turnaround time for long processes, as they are completed first. This can lead to better resource utilization in systems where long-running processes are common. Additionally, LJF can reduce the overall average waiting time for these long processes, making it beneficial for batch processing environments.
3. What are the disadvantages of the LJF scheduling algorithm?
Ans. The LJF scheduling algorithm has several disadvantages. One significant issue is that it can lead to starvation for shorter processes, as they may be indefinitely delayed if longer processes keep arriving. Additionally, predicting the exact run time of processes can be challenging, making the implementation of LJF less practical in dynamic environments. Lastly, it may not be suitable for time-sharing systems where responsiveness is critical.
4. How does LJF compare to other scheduling algorithms like Shortest Job First (SJF)?
Ans. LJF contrasts with Shortest Job First (SJF) scheduling, which prioritizes the shortest processes. While SJF aims to minimize the average waiting time for all processes by completing shorter tasks first, LJF focuses on long jobs, which can lead to longer waiting times for shorter processes. SJF is often more efficient in time-sharing systems, while LJF may be more applicable in batch systems where long processes are expected.
5. In which scenarios is the LJF scheduling algorithm most effectively utilized?
Ans. The LJF scheduling algorithm is most effectively utilized in batch processing systems where jobs have predictable and significant execution times. It is suitable for environments where long processes are common, such as scientific computations or data processing tasks. However, it is less effective in interactive systems or real-time applications where response time is crucial, as it can cause delays for shorter tasks.
Explore Courses for Computer Science Engineering (CSE) exam
Get EduRev Notes directly in your Google search
Related Searches
Free, Exam, shortcuts and tricks, MCQs, mock tests for examination, video lectures, Extra Questions, Semester Notes, Longest Job First (LJF) CPU Scheduling Algorithm, Summary, past year papers, ppt, practice quizzes, Previous Year Questions with Solutions, Viva Questions, Longest Job First (LJF) CPU Scheduling Algorithm, Objective type Questions, Important questions, study material, pdf , Sample Paper, Longest Job First (LJF) CPU Scheduling Algorithm;