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

lec9

The document discusses Shortest-Job-First (SJF) scheduling in operating systems, detailing both non-preemptive and preemptive schemes. It highlights the advantages of SJF, such as optimal average waiting time, and its disadvantages, including practical implementation challenges and potential starvation for longer processes. Additionally, it provides examples and problems related to calculating average waiting and turnaround times for both scheduling types.

Uploaded by

Aryan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

lec9

The document discusses Shortest-Job-First (SJF) scheduling in operating systems, detailing both non-preemptive and preemptive schemes. It highlights the advantages of SJF, such as optimal average waiting time, and its disadvantages, including practical implementation challenges and potential starvation for longer processes. Additionally, it provides examples and problems related to calculating average waiting and turnaround times for both scheduling types.

Uploaded by

Aryan Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

24-01-2025

Lecture 8:SJF Scheduling


Operating Systems
Dr. Anjali
Assistant Professor

Shortest-Job-First (SJF) Scheduling

● Associate with each process the length of its next CPU burst.
Use these lengths to schedule the process with the shortest
time.
● Two Schemes:
● Scheme 1: Non-preemptive
• Once CPU is given to the process it cannot be preempted until it
completes its CPU burst.
● Scheme 2: Preemptive
• If a new CPU process arrives with CPU burst length less than remaining
time of current executing process, preempt. Also called Shortest-
Remaining-Time-First (SRTF).
● SJF is optimal - gives minimum average waiting time for a given set of
processes.

1
24-01-2025

Non-Preemptive SJF Scheduling

● Example

Gantt Chart for Schedule

P1 P3 P2 P4 Average waiting time =


(0+6+3+7)/4 = 4
0 7 8 12 16

Preemptive SJF Scheduling (SRTF)

● Example

Gantt Chart for Schedule


P1 P2 P3 P2 P4 P1 Average waiting time =
0 2 4 5 7 11 (9+1+0+2)/4 = 3
16

Note: SRTF-Shortest Remaining Time First

2
24-01-2025

Advantages-

•SRTF is optimal and guarantees the minimum average waiting time.


•It provides a standard for other algorithms since no other algorithm performs
better than it.

Disadvantages-

•It can not be implemented practically since burst time of the processes can
not be known in advance.
•It leads to starvation for processes with larger burst time.
•Priorities can not be set for the processes.
•Processes with larger burst time have poor response time.

Problem-01:

Consider the set of 5 processes whose arrival time and burst time
are given below-

If the CPU scheduling policy is SJF non-preemptive, calculate the average


waiting time and average turn around time.

3
24-01-2025

Solution-

•Average Turn Around time = (4 + 15 + 5 + 6 + 10) / 5 = 40 / 5 = 8 unit


•Average waiting time = (3 + 11 + 3 + 0 + 7) / 5 = 24 / 5 = 4.8 unit

Problem-02: Consider the 5 processes whose arrival time and burst time
are given below-

If the CPU scheduling policy is SJF preemptive, calculate the average waiting
time and average turn around time.

4
24-01-2025

Solution-

•Average Turn Around time = (1 + 5 + 4 + 16 + 9) / 5 = 35 / 5 = 7 unit


•Average waiting time = (0 + 1 + 2 + 10 + 6) / 5 = 19 / 5 = 3.8 unit

Practice Problem 1

ProcessAarri Arrival TimeT Burst Time


P1 0 8
P2 1 4
P3 2 9
P4 3 5

10

5
24-01-2025

Practice Problem 2

11

Practice Problem 3

12

6
24-01-2025

13

You might also like