We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
10118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
SJF Scheduling | SRTF | CPU Scheduling
Orerng S88 6 IE Scheduling:
In SJF Scheduling,
* Out of all the available processes, CPU is assigned to the process having smallest burst time.
* Incase of a tie, it is broken by FCFS Scheduling.
Shortest Job First
Non-preemptive mode Preemptive mode
(Shortest Remaining Time First)
+ SJF Scheduling can be used in both preemptive and non-preemptive mode.
+ Preemptive mode of Shortest Job First is called as Shortest Remaining Time First (SRTF).
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.
PRACTICE PROBLEMS BASED ON SJF SCHEDULING-
hitpsshwww.galevidyalay.comis-schedulng-sttcpu-scheduting! 1910118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
Problem-01:
Consider the set of 5 processes whose arrival time and burst time are given below-
Process id Arrival Burst
time time
Pt 3 1
P2 1 4
P3 4 2
P4 oO 6
PS 2 3
Ifthe CPU scheduling policy is SJF non-preemptive, calculate the average waiting time and average turn
around time.
Solutio!
Gantt Chart-
0 6 a 9 12 16
[es | oi | rs | es | oe |
Gantt Chart
Now, we know-
+ Tum Around time = Exit time — Arrival time
+ Waiting time = Turn Around time — Burst time
hitpsuiwo galevidyalay.comis-schedulng-st-cpu-schedung! 2910118122, 7:00 PM
Also read- Various Times of Process
SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
Process Exit awn " Waiting
Id time time time
PI 7 7-324
P2 16 15-4=11
P3 9 9-4=5 5-2=3
P4 6 6-0=6 6-6=0
PS 12 12-2=10 10-3=7
Now,
* 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 set of 5 processes whose arrival time and burst time are given below-
Pt
P2
P3
Pa
PS
Process Id
hitpsshwww.galevidyalay.comis-schedulng-sttcpu-scheduting!
Arrival
ti
a910118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
Ifthe CPU scheduling policy is SJF preemptive, calculate the average waiting time and average tum around
time,
Solution-
Gantt Chart-
0 1 3 4 6 8 " 16
P4 P2 P1 P2 P3 PS P4
Gantt Chart
Now, we know-
+ Turn Around time = Exit time — Arrival time
* Waiting time = Turn Around time — Burst time
Process Exit aun d Waiting
Id time time time
Pt 4 =4
p2 6 =5 5-4
P3 8 8-424 4-222
P4 16 16-0=16 | 16-6=10
PS "1 1-259 9-3=6
Now,
* Average Turn Around time = (1 +5 +4 + 16 +9)/5=35/5=7 unit
* Average waiting time = (0+ 1 +24 10+ 6)/5= 19/5 = 3.8 unit
hitpsuiwo galevidyalay.comis-schedulng-st-cpu-schedung! 4910118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
Problem-03:
Consider the set of 6 processes whose arrival time and burst time are given below-
Process id Arrival Burst
Pt oO 7
P2 1 5
P3 2 3
P4 3 1
PS 4 2
P6 5 1
Ifthe CPU scheduling policy is shortest remaining time first, calculate the average waiting time and average
turn around time.
Solution-
Pi P2 P3 P4 P3 P6 rs P2 Pi
Gantt Chart
Now, we know-
* Tum Around time =
xit time — Arrival time
* Waiting time = Turn Around time — Burst time
hitpsuiwo galevidyalay.comis-schedulng-st-cpu-schedung! 5910118122, 7:00 PM ‘SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
Prewess Gxt ground an
time
P41 19 19-0=19 19-7 =12
P2 13 12-5=7
P3 6
P4 4
PS 9 9-4=5 5-2=3
Now,
+ Average Tur Around time = (19 + 12+4+1+5+2)/6=43/6=7.17 unit
* Average waiting time = (12+7+1+0+3+1)/6=24/6=4 unit
Problem-04:
Consider the set of 3 processes whose arrival time and burst time are given below-
Process Arrival | Burst
Id time time
Pt 0 9
P2 1 4
P3 2 9
If the CPU scheduling policy is SRTF, calculate the average waiting time and average tum around time,
Solutio:
Gantt Chart:
hitpsuiwo galevidyalay.comis-schedulng-st-cpu-schedung! 6910118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
0 1 5 13 22
[er | ee | os | rs |
Gantt Chart
Now, we know-
+ Turn Around time = Exit time — Arrival time
+ Waiting time = Turn Around time — Burst time
Pregess Eat grind alia
time
Now,
* Average Turn Around time = (13 +4 + 20)/3 = 37/3 = 12.33 unit
* Average waiting time = (4 +0 + 11)/3 = 15/3 =5 unit
Problem-05:
Consider the set of 4 processes whose arrival time and burst time are given below-
Arrival Burst
Process Id time
Pt 0 20
P2 15 25
hitpsuiwow galevidyalay.comis-schedulng-st-cpu-schedungl 7910118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
P3 30 10
Pa 45 15
Ifthe CPU scheduling policy is SRTF, calculate the waiting time of process P2.
Solution-
Gantt Chart-
0 20 30 40 55 70
Gantt Chart
Now, we know-
* Tur Around time = Exit time — Arrival time
* Waiting time = Turn Around time — Burst time
Thus,
+ Turn Around Time of process P2 = 55 — 15 = 40 unit
* Waiting time of process P2 = 40 — 25 = 15 unit
Implementation of Algorithm-
+ Practically, the algorithm can not be implemented but theoretically it can be implemented
+ Among all the available processes, the process with smallest burst time has to be selected
* Min heap is a suitable data structure where root element contains the process with least burst time.
+ Inmin heap, each process will be added and deleted exactly once.
+ Adding an element takes log(n) time and deleting an element takes log(n) time.
hitpsshwww.galevidyalay.comis-schedulng-sttcpu-scheduting!10118122, 7:00 PM SUF Scheduling | SRTF | CPU Sehedullng | Gate Vidyalay
+ Thus, forn processes, time complexity = n x 2log(n) = nlog(n)
hitpsuiwo galevidyalay.comis-schedulng-st-cpu-schedung! 99