SJF is used primarily to minimize the average waiting time of
processes, thus improving system performance. It is particularly
effective in scenarios where there's a mix of short and long
processes. By prioritizing shorter processes, SJF aims to optimize
system throughput and response time.
Shortest job first
Shortest-Job-First Scheduling is said to be the best process
scheduling approach as it minimizes the waiting time of the other
processes awaiting their execution. It is also referred to as
Shortest-Job-Next owing to its characteristic of scheduling the job
with the minimum time as next. It is both pre-emptive and
non-preemptive.
characteristics of SJF
It suits best in Batch-type Systems where the CPU time i.e,
Burst Time, is known beforehand and process execution is not
that critical.
It is associated with each process as a time to be completed.
It can increase output by offering a short process time, i.e
the short processes are executed first.
Since the jobs that need less time are executed first, it also
increases the throughput time.
The algorithm works best when the arrival time for all
processes is the same.
Advantages & Disadvantages
Advantages :
Minimizes Average Waiting Time: SJF scheduling algorithm
selects the process with the smallest execution time, leading
to shorter waiting times for processes overall.
Optimal for Certain Workloads: In situations where there are
mostly short processes mixed with a few long ones, SJF tends
to perform very well, as it prioritizes short jobs, allowing
them to complete quickly.
Improves System Throughput: By quickly executing short
processes, SJF can increase the number of processes completed
per unit time, enhancing overall system throughput.
Disadvantages :
Prediction Issues: SJF requires accurate estimation or
knowledge of the execution time of each process, which might
not always be available. If there's uncertainty in process
execution times, it can lead to poor performance.
Possibility of Starvation: Long processes may never get
executed if short processes continually arrive, leading to
starvation.
Pre-emption Overhead: Implementing SJF with pre-emption
(where a shorter job arrives while a longer job is
executing) can introduce overhead due to frequent context
switches.
Terminology Required for SJF Table
Arrival Time: The time at which a process arrives in the ready
queue for execution.
Burst Time: The amount of time a process requires for execution
from start to finish.
Finish Time: The time at which a process completes its
execution.
Turnaround Time: The total time taken by a process from arrival
to completion, including waiting time and execution time.
Turn Around Time = Completion Time - Arrival Time
Waiting Time: The total time a process spends waiting in the
ready queue before it gets CPU time for execution.