Skip to content

Latest commit

 

History

History
14 lines (11 loc) · 1.27 KB

2.1 Shortest_job_first.md

File metadata and controls

14 lines (11 loc) · 1.27 KB

Shortest Job First (SJF) is a CPU scheduling algorithm in which processes are executed in order of their length, i.e., the amount of CPU time they require. The shortest process is executed first, followed by the next shortest process, and so on. This algorithm aims to minimize the average waiting time and turnaround time of processes.

Here is a high-level overview of how the SJF algorithm works:

  • When a process arrives, its length is determined (either by its burst time or an estimate based on past behavior).
  • The process is added to the ready queue.
  • The CPU is assigned to the process with the shortest length in the ready queue.
  • The process is executed until it completes or is blocked.
  • If the process completes, it is removed from the queue.
  • If the process is blocked, it is moved to a blocked queue and the CPU is assigned to the process with the shortest length in the ready queue.
  • When the blocked process becomes unblocked (e.g., I/O completes), its length is updated and it is moved back to the ready queue.
  • Steps 3-7 are repeated until all processes have completed.

The SJF algorithm can be implemented using a priority queue, which maintains the order of processes based on their length. Processes with shorter lengths have higher priority and are executed first.