0% found this document useful (0 votes)
26 views

Shortest Job First SJF Algorithm PRESENTATION

The document discusses the Shortest Job First (SJF) algorithm, a CPU scheduling technique that prioritizes jobs based on their burst time to minimize waiting and turnaround times. It outlines both preemptive and non-preemptive versions of the algorithm, providing examples and calculations for average waiting times. The advantages and disadvantages of each approach are also compared, highlighting efficiency and fairness in preemptive SJF versus simplicity and potential starvation in non-preemptive SJF.

Uploaded by

eshabbir03
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Shortest Job First SJF Algorithm PRESENTATION

The document discusses the Shortest Job First (SJF) algorithm, a CPU scheduling technique that prioritizes jobs based on their burst time to minimize waiting and turnaround times. It outlines both preemptive and non-preemptive versions of the algorithm, providing examples and calculations for average waiting times. The advantages and disadvantages of each approach are also compared, highlighting efficiency and fairness in preemptive SJF versus simplicity and potential starvation in non-preemptive SJF.

Uploaded by

eshabbir03
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Shortest Job

First (SJF)
Algorithm
GROUP MEMBERS
EMAN SHABBIR (4394-FBAS/BSCS/F 21 A)

IQRA SAJID (4398-FBAS/BSCS/F 21 A)

ALEEMA ANWAR (4402-FBAS/BSCS/F 21 A)

HINA BATOOL (4408-FBAS/BSCS/F 21 A)


Introduction
to Shortest
Job First
(SJF)
Algorithm
The Shortest Job First (SJF) algorithm is a CPU
scheduling technique that prioritizes jobs or
processes based on their estimated or actual burst
time. It aims to minimize the average waiting time
and turnaround time for processes in a computer
system.
Preemptive SJF Algorithm

1 Step 1

Arrival of a new process: The system checks if the new


process has a shorter burst time than the currently
running process.

2 Step 2
If the new process has a shorter burst time, the currently
running process is preempted (interrupted) and the new
process is executed.

3 Step 3

The preempted process is added back to the ready


queue and will be executed when it becomes the
shortest job available.
Example of Preemptive SJF
Process Arrival Time Burst Time Execution Order

P1 0 ms 7 ms P1 (2 ms)

P2 2 ms 4 ms P2 (4 ms)

P3 4 ms 1 ms P3 (5 ms)

P4 5 ms 4 ms P2 (7 ms)

P4 (11 ms)

P1 (16 ms)

now, average waiting time = (completion time- burst time- arrival time)/total no. of processes

average waiting time = ((16-7-0)+(7-4-2)+(5-1-4)+(11-4-5))/4 = (9+1+0+2)/4 = 3


Advantages of Preemptive SJF

Fairness Improved Reduced


Efficiency Starvation
Shorter jobs are
prioritized, Preemptive SJF Preemption allows
ensuring a fair optimizes the use shorter jobs to be
of CPU resources executed
distribution of
by executing the
CPU time and immediately,
shortest job first,
preventing longer reducing the reducing the risk
jobs from average waiting of longer jobs
time and starving and
monopolizing the
turnaround time.
system waiting
indefinitely.
Non-Preemptive SJF Algorithm

Step 1 Step 3

Arrival of a new process: The The currently running


system checks the burst time process will complete its
of the new process and the execution before the new,
currently running process. shorter process is scheduled.

1 2 3

Step 2
If the new process has a
shorter burst time, it is added
to the ready queue but will not
interrupt the currently running
Example of Non-Preemptive SJF
Process Arrival Time Burst Time Execution Order

P1 0 ms 9 ms P1 (9 ms)

P2 3 ms 7 ms P3 (10 ms)

P3 5 ms 1 ms P2 (17 ms)

P4 6 ms 7 ms P4 (24 ms)

now, average waiting time = (completion time- burst time- arrival time)/total no. of processes

average waiting time = ((9-9-0)+(17-7-3)+(10-1-5)+(24-7-6))/4 = (0+7+4+11)/4 = 11/2 = 5.5


Advantages and
Disadvantages of Non-
Preemptive SJF

Advantages Disadvantages
Simpler to implement, less Increased average waiting time,
overhead, and better for CPU- potential for starvation of longer
bound processes. jobs, and less responsive to
changing system conditions.
Conclusion and Comparison of
Preemptive and Non-Preemptive
SJF
Preemptive SJF Non-Preemptive SJF

Optimizes CPU utilization, reduces average Simpler to implement and better for CPU-
waiting time, and prevents starvation. bound processes.

More complex to implement and may Increased average waiting time and
introduce additional overhead. potential for starvation of longer jobs.
PROJECT
OUTPUT
THANK YOU

You might also like