0% found this document useful (0 votes)
6 views21 pages

OS_L5

The document discusses CPU scheduling algorithms, focusing on preemptive and non-preemptive scheduling, including First Come First Serve (FCFS), Shortest Job First (SJF), and Shortest Remaining Time First (SRTF). It explains the advantages and disadvantages of each algorithm, provides examples for calculating average waiting time and turnaround time, and highlights issues like starvation and the convoy effect. The document serves as a lecture on process management in operating systems.
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)
6 views21 pages

OS_L5

The document discusses CPU scheduling algorithms, focusing on preemptive and non-preemptive scheduling, including First Come First Serve (FCFS), Shortest Job First (SJF), and Shortest Remaining Time First (SRTF). It explains the advantages and disadvantages of each algorithm, provides examples for calculating average waiting time and turnaround time, and highlights issues like starvation and the convoy effect. The document serves as a lecture on process management in operating systems.
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/ 21

Process Management

(CPU Scheduling Algorithms)


Lecture-5
CONTENTS

• Preemptive Vs non-preemptive scheduling.


• FCFS scheduling.
• SJF scheduling.
• SRTF scheduling.
Preemptive Vs non-preemptive scheduling.

• 1. Preemptive Scheduling:
• Preemptive scheduling is used when a process switches from running state
to ready state or from the waiting state to ready state.
• The resources (mainly CPU cycles) are allocated to the process for a
limited amount of time and then taken away, and the process is again
placed back in the ready queue if that process still has CPU burst time
remaining.
• That process stays in the ready queue till it gets its next chance to execute.
• 2. Non-Preemptive Scheduling:
• In this scheduling, once the resources (CPU cycles) are allocated to a
process, the process holds the CPU till it gets terminated or reaches a
waiting state.
• In the case of non-preemptive scheduling, the OS does not interrupt a
process running in the CPU in the middle of the execution. Instead, it waits
till the process completes its CPU burst time, and then it can allocate the
CPU to another process.
First Come First Serve (FCFS) CPU scheduling algorithm
• First come first serve (FCFS) scheduling algorithm simply schedules the
jobs according to their arrival time.
• The job which comes first in the ready queue will get the CPU first.
• The lesser the arrival time of the job, the sooner will the job get the CPU.
• FCFS scheduling may cause the problem of starvation if the burst time of
the first process is the longest among all the jobs.
• Advantages of FCFS
• Simple
• Easy
• Disadvantages of FCFS
• The scheduling method is non preemptive, the process will run to the
completion.
• Due to the non-preemptive nature of the algorithm, the problem of
starvation may occur.
• Although it is easy to implement, but it is poor in performance since the
average waiting time is higher as compare to other scheduling
algorithms.
Cont..

Q. Consider the following set of processes that arrive at time 0, with the
length of the CPU burst time given in millisecond as:
Process Burst Time
P1 24
P2 3
P3 3
Calculate the average waiting time using the FCFS CPU scheduling algorithm.
Solution:
Cont..
• If the process arrive in the order P2, P3, P1, then the average WT will be
(0+3+6)/3 = 3ms.
• Thus, the average WT under FCFS policy is generally not minimal and
may vary substantially if the processes CPU burst time vary.

Q. Consider the following set of process with the BT given in ms.

Calculate average WT and average TAT using the FCFS scheduling.


Ans:
Cont..
• Turn Around Time = Completion Time - Arrival Time
• Waiting Time = Turnaround time - Burst Time

• Average TAT = (2+7+10+18+29)/5 = 13.3 ms.


• Average WT = (0+1+6+9+15)/5 = 6.2 ms.
Cont..
• Convoy Effect in FCFS
• FCFS may suffer from the convoy effect if the burst time of the first
job is the highest among all.
• If the CPU gets the processes of the higher burst time at the front
end of the ready queue then the processes of lower burst time may
get blocked which means they have to wait for a longer period of
time to get the CPU if the job in the execution has a very high burst
time. This is called convoy effect.
Cont..
Q. Consider the set of 5 processes whose arrival time and burst time are
given below-

If the CPU scheduling policy is FCFS, calculate the average waiting time and
average turn around time.
Ans: Average Turn Around time = (4 + 8 + 2 + 9 + 6) / 5 = 29 / 5 = 5.8 unit
Average waiting time = (0 + 5 + 0 + 8 + 3) / 5 = 16 / 5 = 3.2 unit
Shortest Job First (SJF) scheduling
• Till now, we were scheduling the processes according to their arrival time
(in FCFS scheduling). However, SJF scheduling algorithm, schedules the
processes according to their burst time.
• In SJF scheduling, the process with the lowest burst time, among the list of
available processes in the ready queue, is going to be scheduled next.
• However, it is very difficult to predict the burst time needed for a process
hence this algorithm is very difficult to implement in the system.

• Advantages of SJF
• Maximum throughput
• Minimum average waiting and turnaround time

• Disadvantages of SJF
• May suffer with the problem of starvation
• It is not implementable because the exact Burst time for a process can't be
known in advance.
Cont..

Q. Consider the following set of processes that arrive at time 0, with the
length of the CPU burst time given in millisecond as:
Process Burst Time
P1 6
P2 8
P3 7
P4 3
Calculate the average waiting time using the SJF CPU scheduling algorithm.
Cont..
• Q. 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 turnaround time.

• Ans:
Cont..

• 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
Cont..
Q. In the following example, there are five jobs named as P1, P2, P3, P4
and P5. Their arrival time and burst time are given in the table below.
Consider the SJF non-preemptive scheduling; calculate average WT,
TAT, and CT.

• Average TAT = 11.4


• Average WT = 5.4
Shortest Remaining Time First (SRTF)
Scheduling
• This Algorithm is the preemptive version of SJF scheduling.
• In SRTF, the execution of the process can be stopped after
certain period of time.
• At the arrival of every process, the short term scheduler
schedules the process with the least remaining burst time
among the list of available processes and the running process.
• Once all the processes are available in the ready queue, No
preemption will be done and the algorithm will work as SJF
scheduling.
Cont..
• There are five jobs P1, P2, P3, P4, P5 and P6. Their arrival time and burst
time are given below in the table. Calculate the average WT using the
SRTF algorithm.
Cont..
• Since, at time 0, the only available process is P1 with CPU burst time 8. This is
the only available process in the list therefore it is scheduled.
• The next process arrives at time unit 1. Since the algorithm we are using is SRTF
which is a preemptive one, the current execution is stopped and the scheduler
checks for the process with the least burst time.
Till now, there are two processes available in the ready queue. The OS has
executed P1 for one unit of time till now; the remaining burst time of P1 is 7
units. The burst time of Process P2 is 4 units. Hence Process P2 is scheduled on
the CPU according to the algorithm.
• The next process P3 arrives at time unit 2. At this time, the execution of process
P3 is stopped and the process with the least remaining burst time is searched.
Since the process P3 has 2 unit of burst time hence it will be given priority over
others.
• The Next Process P4 arrives at time unit 3. At this arrival, the scheduler will stop
the execution of P4 and check which process is having least burst time among
the available processes (P1, P2, P3 and P4). P1 and P2 are having the remaining
burst time 7 units and 3 units respectively.
• P3 and P4 are having the remaining burst time 1 unit each. Since, both are equal
hence the scheduling will be done according to their arrival time. P3 arrives
earlier than P4 and therefore it will be scheduled again.
Cont..
• The Next Process P5 arrives at time unit 4. Till this time, the Process P3 has
completed its execution and it is no more in the list. The scheduler will compare the
remaining burst time of all the available processes. Since the burst time of process
P4 is 1 which is least among all hence this will be scheduled.
• The Next Process P6 arrives at time unit 5, till this time, the Process P4 has
completed its execution. We have 4 available processes till now, that are P1 (7), P2
(3), P5 (3) and P6 (2). The Burst time of P6 is the least among all hence P6 is
scheduled. Since, now, all the processes are available hence the algorithm will now
work same as SJF. P6 will be executed till its completion and then the process with
the least remaining time will be scheduled.
• Once all the processes arrive, No preemption is done and the algorithm will work
as SJF

• Average WT = 24/6.
Cont..
• Q. Consider the set of 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 turnaround time.
Cont..

• Now, we know-
• Turn Around time = Exit time – Arrival time
• Waiting time = Turn Around time – Burst time

• 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
Cont..
• Q. Consider the set of 6 processes whose arrival time and burst time are
given below. If the CPU scheduling policy is shortest remaining time
first, calculate the average waiting time and average turnaround time.
(Home Work)

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