SHORTEST JOB FIRST ALGORITHM



The Shortest Job First (SJF) is a scheduling policy that selects the waiting process with the smallest execution time to execute next. It is also known as Shortest Job Next (SJN) or Shortest Process Next (SPN). It is a non-preemptive scheduling algorithm.



Shortest Job First (SJF)


➢It is associated with each job as a unit of time to complete.
➢This algorithm method is helpful for batch-type processing, where waiting for jobs to complete is not critical.
➢It can improve process throughput by making sure that shorter jobs are executed first, hence possibly have a short turnaround time.
➢It improves job output by offering shorter jobs, which should be executed first, which mostly have a shorter turnaround time



Suppose there are three processes in a queue: P1, P2 and P3.All these three processes are sorted according to arrival time then process with lowest arrival time will get executed first.For later processes burst time will be sorted and the process with lowest burst time and with arrival time less than completion time of previous process will be given the CPU first.







EXAMPLE OF FCFS



PROCESS ARRIVAL TIME BURST TIME
P1 0.0 7
P2 2.0 4
P3 4.0 1
P4 5.0 4


The Gantt Chart of the given example is:




Turn around time
=(24+27+30)/3
=27



To simulate the algorithm:

SIMULATE