SJF: Shortest Job First Scheduling Algorithm

 

SJF: Shortest Job First Scheduling Algorithm

What is Shortest Job First (SJF) Algorithm?


Shortest Job First (SJF) is an algorithm of scheduling which provide more efficiency to share CPU for every process.

 

In SJF lowest execution time is selecting for the upcoming process to execute. SJF can be Preemptive and non-preemptive. This scheduling algorithm is faster then FCFS. SJF is stands for Shortest Job First.


Let’s understand more about this suppose you have four process in waiting stats and that are P1, P2, P3 and P4 and they takes time to execute in order to 3ms, 1ms, 4ms and 2ms.


So P2 has shortest execution time so that process execute first then P4 then P1 and then P3. Mainly there are two types of SJF scheduling Algorithm let’s see both..


Types of SJF


1.Non-Preemptive

2.Preemptive 


Non-Preemptive SJF


In non-preemptive scheduling when CPU assign to the process then the process holds the CPU until the process is terminated or reaches the waiting state.


Preemptive SJF


In preemptive scheduling when CPU assign to the process then if in any case process takes more time then usually then at this point if we want to take back the CPU from process it allows us to take back then it calls preemptive scheduling. 


Question Mostly asked


1. Is SRTF and SJF same?

Ans: Yes the full form of SRTF is Shortest Remaining Job First so in this case if there is three process then all have different execution time so it execute shortest remaining job first so both SRTF and SJF is same.


2. What is the Full form of SJF? 

Ans: Shortest Job First


3. How do you calculate TurnAround time?

Ans: TurnAround Time = Burst Time + Waiting Time.


4. What is the drawback/disadvantage of SJF algorithm?

Ans: It is necessary that the time taken by the process must be known in advance by the CPU which is difficult and hard. Longer processes will have longer waiting times, eventually they will never get the processor on time they need to wait so much.

Reactions

Post a comment

0 Comments