0% found this document useful (0 votes)
23 views10 pages

CPU Scheduling SJF RSJF Dated 07-08-2024

The document discusses Shortest Job First (SJF) scheduling, an optimal algorithm that minimizes average waiting time by allocating CPU to the process with the shortest next CPU burst. It explains the differences between preemptive and non-preemptive SJF, provides examples with Gantt charts, and includes calculations for completion, turnaround, and waiting times for various processes. The document emphasizes the challenge of knowing the length of the next CPU request as a disadvantage of SJF.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views10 pages

CPU Scheduling SJF RSJF Dated 07-08-2024

The document discusses Shortest Job First (SJF) scheduling, an optimal algorithm that minimizes average waiting time by allocating CPU to the process with the shortest next CPU burst. It explains the differences between preemptive and non-preemptive SJF, provides examples with Gantt charts, and includes calculations for completion, turnaround, and waiting times for various processes. The document emphasizes the challenge of knowing the length of the next CPU request as a disadvantage of SJF.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Operating System

Dr. Akhtar Husain


Associate Professor in Department of CSIT,
Faculty of Engineering and Technology,
MJP Rohilkhand University, Bareilly, U.P., India.
Mobile : 9457381048, 9319760019
Email: akhtarhusain@mjpru.ac.in
Shortest Job First-SJF Scheduling
 Introduced to solve the problem having long waiting time of
FCFS when requests of short CPU burst waits behind the long
ones.
 Associate with each process the length of its next CPU burst
 Use these lengths to schedule the process with the
shortest time
 When the CPU is available , it is allocated to process that
has the smallest next CPU burst.
 In the case of if two processes has same CPU bursts , then
FCFS concept is applied.
 SJF is optimal – gives minimum average waiting time for a given
set of processes
 The difficulty is knowing the length of the next CPU request

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
• SJF is also called shortest next CPU burst scheduling algorithm,
because this scheduling is done by examining the next CPU burst of
a process rather than its total length.

• This algorithm is considered to be Optimal Algorithm because


it provides minimum average waiting time.

• The disadvantage of SJF is to know the length of time for which


CPU is needed by a process.

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
• SJF may be preemptive or non-preemptive, this condition arises
when a new process enters in the ready queue while a previous
process is executing.

• preemptive SJF will stop currently executing process and starts the
execution of newly entered process. Its also called Shortest
Remaining Time First (SRTF).

• non-preemptive SJF will allow the currently executing process to


complete its burst time without any interruption in its execution.

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
SJF Scheduling Examples

Process Burst Time


P1 3
P2 5
P3 2
P4 5
P5 5
 Case 1: When all the processes enter into the ready queue at the same
time i.e. at 0 ms.

SJF Gantt Chart


P3 P1 P2 P4 P5

0 2 5 10 15

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Calculations
Process Burst Time (BT) ms Arrival Time Completion Time Turn Around Time Waiting Time
Number (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 3 0 5 5 2

P2 5 0 10 10 5

P3 2 0 2 2 0

P4 5 0 15 15 10

P5 5 0 20 20 15

Average =(5+10+2+15+20)/5 =(2+5+0+10+15)/5


=52/5=10.4 ms =32/5=6.4 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
SJF Scheduling Examples when arrival
time is given
Process Burst Time
P1 3
P2 5
P3 2
P4 5
P5 5

 Case 2 for Non-preemptive Scheduling : When all the processes enter


into the ready queue at times i.e. at 0 ms, 1 ms, 3 ms, 9 ms and 12 ms
respectively.

Gantt Chart
P1 P3 P2 P4 P5

0 3 5 10 15 20

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Calculations
Process Burst Time (BT) Arrival Time Completion Time Turn Around Time Waiting Time
Number ms (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 3 0 3 3 0

P2 5 1 10 9 4

P3 2 3 5 2 0

P4 5 9 15 6 1

P5 5 12 20 8 3

Average =(3+9+2+6+8)/5 =(0+4+0+1+3)/5


=28/5=5.6 ms =8/5=1.6 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
SJF Scheduling Examples when arrival
time is given
Process Burst Time
P1 5
P2 1
P3 2
P4 5
P5 5

 Case 3 for preemptive Scheduling : When all the processes enter into
the ready queue at times i.e. at 0 ms, 1 ms, 3 ms, 9 ms and 12 ms
respectively.

Gantt Chart
P1 P2 P1 P3 P1 P4 P5

0 1 2 3 5 8 9 14 19

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education
Calculations
Process Burst Time (BT) Arrival Time Completion Time Turn Around Time Waiting Time
Number ms (AT) ms (CT) ms (TAT=CT-AT) ms (WT=TAT-BT) ms

P1 5 0 8 8 3

P2 1 1 2 1 0

P3 2 3 5 2 0

P4 5 9 14 5 0

P5 5 12 19 7 2

Average =(8+1+2+5+7)/5 =(3+0+0+0+2)/5


=23/5=4.6 ms =5/5=1 ms

Sources: 1.Silberschatz, Galvin and Gagne, ―Operating Systems


Concepts‖, Wiley 2:Harvey M Dietel, ― An Introduction to
Operating System‖, Pearson Education

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy