• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 23, 2024 |950 Views

Shortest Job First (SJF) Scheduling Algorithm | Operating Systems

Description
Discussion

In this video, we will be studying the Shortest Job First (SJF) CPU Scheduling Algorithm.

What is CPU Scheduling?
The process of assigning CPU time to various processes is known as CPU Scheduling. It allows the CPU to execute a process while another process is kept on standby (or is waiting for other system resources). Scheduling improves CPU utilization by reducing idle time. It enhances the efficiency of the system by making it faster and more responsive. 

When the CPU becomes idle, the OS must select one of the processes that are ready to be executed. The selection process is performed by the CPU scheduler. The CPU Scheduler selects one of the processes present in memory and assigns the CPU to it. The algorithm used by the CPU Scheduler to select the process is known as the CPU Scheduling (or Process Scheduling) Algorithm.

Shortest Job First (SJF) algorithm selects the process that has the smallest burst time for assigning the CPU next. It is a greedy algorithm which makes scheduling decisions based on burst times of the processes. SJF is a non-preemptive scheduling algorithm. Once a process is scheduled, it is not interrupted even if a shorter process arrives. It is also known as Shortest Job Next scheduling algorithm.

Advantages of SJF:

1) It reduces the average waiting time as compared to FCFS algorithm. 
2) It is suitable for jobs that run in batches, as their execution time is already known. 
3) It is useful for long-term scheduling of processes. 
4) It reduces the average turnaround time of processes. 
5) It achieves a high throughput, leading to efficient CPU utilisation.

It can lead to starvation of processes if shorter jobs keep entering the system and are selected by the scheduler. Estimating the burst time for all the processes may not be feasible. Difficult to implement as it requires predicting the burst time of processes in advance.

Shortest Job First (SJF) CPU Scheduling:
https://www.geeksforgeeks.org/program-for-shortest-job-first-or-sjf-cpu-scheduling-set-1-non-preemptive/