Shortest Job First Scheduling SJF Process Scheduling in operating systems

Shortest Job First Scheduling SJF Process Scheduling in operating systems.

The process with less burst time will always execute first.

This is a non-preemptive scheduling algorithm so processes priority does not matter.

Preferred to minimize waiting time.

Better than First come first served scheduling.

Works only when the processor knows in advance that how much time every process will take to execute on CPU.

Not preferred for interactive systems because required CPU time is not already in knowledge.

Easy to implement in Batch systems because in batch systems CPU time is already known. 

Process Burst Time Arrival
P1 4 2nd
P2 2 3rd
P3 8 1st
P4 3 4th

Gantt Chart Diagram of Short Job First Scheduling (SJF)

Let us see the Gantt Chart Diagram of Short Job First Scheduling (SJF).

Shortest Job First gamtt chart diagram

Process Waiting Time
P1 5
P2 0
P3 9
P4 2

Average Wait Time: (0+2+5+9) / 4 = 4

How to calculate turn around time?

TurnAroundTime = BurstTime + WaitingTime.

Program of Shortest Job First Scheduling (SJF) in C Language

Code of SJFS

 

Output

SJF Scheduling program in C++
SJF implementation in Java

Let us see the SJF implementation in Java.

Video Lecture

By: Prof. Fazal Rehman Shamil    CEO @ T4Tutorials
Whatsapp: +92 302 87 000 85     Facebook: For Discussions

Leave a Reply

Your email address will not be published. Required fields are marked *