SJF Scheduling Program in C

SJF Scheduling Program in C

Here you will learn SJF Scheduling and, the program code of SJF Scheduling Program in C programming language.

SJF scheduling

 

sjf scheduling in os

Shortest Job First (SJF) is a scheduling algorithm used in operating systems to manage processes. It is a nonpreemptive algorithm, which means that once a process has started running, it cannot be interrupted until it has completed its task. The aim of SJF is to minimize the average waiting time of processes.

The algorithm works by sorting the processes by their burst time and then scheduling them in the order of shortest burst time first. This ensures that the processes with the shortest burst time are executed first and thus the average waiting time is minimized.

 

SJF scheduling can be used in preemptive and non-preemptive mode. The preemptive mode of Shortest Job First is called as Shortest Remaining Time First (SRTF).

 

Non-Preemptive SJF

Non-preemptive SJF is a scheduling algorithm that works by having the process with the shortest job run first. This means that the process with the shortest job will run until it is completed before the next process can start. This algorithm helps reduce waiting time and is known to be one of the most efficient scheduling algorithms.
Process QueueBurst timeArrival time
P162
P225
P381
P430
P544
 gantt chart for SJF Scheduling

Wait time
P4= 0-0=0
P1= 3-2=1
P2= 9-5=4
P5= 11-4=7
P3= 15-1=14

Average Waiting Time =  0+1+4+7+14/5 = 26/5 = 5.2

 

Preemptive SJF

In Preemptive SJF Scheduling, jobs are processed in queue as they come. A process with shortest burst time start execution. If a process has a shorter burst duration, it takes the place of the one that is now running and gets a CPU cycle for the shorter task.
Process with following table:
Process QueueBurst timeArrival time
P162
P225
P381
P430
P544
gt2
Wait time
P4= 0-0=0
P1=  (3-2) + 6 =7
P2= 5-5 = 0
P5= 4-4+2 =2
P3= 15-1 = 14
Average Waiting Time = 0+7+0+2+14/5 = 23/5 =4.6

 

SJF scheduling example

Output

SJF scheduling program in c output

 

Read Also

 

 

2 thoughts on “SJF Scheduling Program in C”

Leave a Comment

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

Scroll to Top