0% found this document useful (0 votes)
17 views61 pages

OS UNIT 2 CPU Scheduling

The document discusses various types of CPU scheduling algorithms, including preemptive and non-preemptive methods, and their criteria for performance evaluation. It covers specific algorithms such as First Come First Serve (FCFS), Shortest Job First (SJF), Round Robin (RR), and Priority Scheduling, detailing their advantages and disadvantages. Additionally, it touches on real-time scheduling and the roles of different types of schedulers in managing process execution.
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)
17 views61 pages

OS UNIT 2 CPU Scheduling

The document discusses various types of CPU scheduling algorithms, including preemptive and non-preemptive methods, and their criteria for performance evaluation. It covers specific algorithms such as First Come First Serve (FCFS), Shortest Job First (SJF), Round Robin (RR), and Priority Scheduling, detailing their advantages and disadvantages. Additionally, it touches on real-time scheduling and the roles of different types of schedulers in managing process execution.
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/ 61

UNIT 2

By
Amandeep Kaur
TOPICS
• Types of Schedulers
• Scheduling Algorithms (Pre-emptive and Non-Preemptive..NP) & Criteria
• Dispatcher
• First Come First Serve (FCFS), Shortest Job First (SJF) under NP
• Round Robin (RR), Priority Scheduling (PS), Multi Level Feedback Queue (MLFQ)
under Pre-emptive
• Multiprocessor Scheduling (MS)
• Real Time Scheduling (RTS)
• Thread Scheduling (TS)
Why
• To maximize CPU utilization.
• Context Switching
• The aim of processor scheduling is to assign
Scheduli processes to be executed by the processor.
• Scheduling affects the performance of the

ng? system, because it determines which process


will wait and which will progress.
• Degree of Multi-Programming: It tells us
how many processes a single-processor system
can handle well.
Schedul
• The process of selecting processes
among these queues (done by
selector i.e. scheduler) is carried
out by a dispatcher.

er and • 3 Types of (Scheduler &


Queues):

its types
• Long-Term Scheduling or Job
Scheduler. i.e. Ready Queue
• Medium-Term Scheduling or
Swapping Scheduler i.e. Waiting
Queue
• Short-Term Scheduling or CPU
Scheduler. i.e. Running Queue
TYPES OF SCHEDULERS
LTS,STS,MTS
Which of the following best describes the function of
short-term scheduling (STS) in an operating system?

A) Selects which process should be brought into the ready queue from the job pool.
B) Selects which process should be swapped out of the main memory to the
secondary storage.
C) Selects which process should be executed next by the CPU from the ready
queue.
D) Determines which process should be terminated to free up resources.
ANS: C
C) Selects which process should be executed next by the CPU from the ready
queue.

Short-Term Scheduling (STS): Determines which process in the ready


queue should be executed next by the CPU.
Long-Term Scheduling (LTS): Controls the admission of processes into the
ready queue from the job pool.
Medium-Term Scheduling (MTS): Manages the swapping of processes in
and out of main memory (related to the concept of swapping).
Why
Schedulin
g
Criteria ?
• Scheduling criteria is also called as
scheduling methodology. Key to
multiprogramming is scheduling.

Schedulin • Different CPU scheduling algorithm have


different properties .

g Criteria • The criteria used for comparing these


algorithms include the following:
• CPU Utilization: Keep the CPU as busy as
possible. It range from 0 to 100%. In practice,
it range from 40 to 90%.
• Throughput: Throughput is the rate at which
processes are completed per unit of time.
SCHEDULING CRITERIA
• Arrival Time (AT): The time at which • AT: Arrival Time
the process enter into RAM or Ready • BT: Burst Time i.e. Run Time or
Queue. Execution Time
• Burst Time (BT): It refers to the • CT: Completion Time
time required by a process to get
executed on a CPU. i.e. time duration • TAT: Turn Around Time (TAT=CT-AT)
• Completion Time (CT): The time at • WT: Waiting Time (WT=TAT-BT)
which the process get completed. i.e. • RT: Response Time (RT=ST-AT)
(end time or completion time of
process)
• Avg. TAT= Sum(TAT)/n(P)
• Avg. WT= Sum(WT)/n(P)
Which of the following scheduling criteria is
concerned with the time a process takes from
submission to completion?

A. CPU utilization
B. Throughput
C. Turn Around Time
D. Waiting time
ANS. C
C. Turnaround time
• Scheduling algorithms or scheduling policies are
mainly used for short-term scheduling and the main
objective of short-term scheduling is to allocate

Schedulin
processor time in such a way as to optimize one or
more aspects of system behavior.

g
• For these scheduling algorithms assume only a single
processor is present.
• Scheduling algorithms decide which of the processes in
Algorithm the ready queue is to be allocated to the CPU is basis
on the type of scheduling policy and whether that
s policy is either preemptive or non-preemptive. For
scheduling arrival time and service time are also will
play a role.
NP( • FCFS (First-come First Served)
NON • SJF (Shortest Job First )
-
PRE
MPTI

Schedulin
VE)
• SRTF (Shortest Remaining Time First)
• PRIORITY

g PRE
EMP
TIVE


RR (Round-Robin)
MLFQ (Multilevel Feedback Queue)

Algorithm
s
• MULTIPROCESSOR
• RT (Real Time )
• THREAD
MIX
GANTT CHART (GC)
• It is simply used for
graphical representation
of schedule .
• A Gantt chart is a
horizontal bar chart used
to represent operating
systems CPU scheduling in
graphical view that help
to plan, coordinate and
track specific CPU utilization
factor like throughput,
waiting time, turnaround
time etc.
FIRST COME FIRST SERVED
FCFS: SCHEDULING (FCFS)
• The process which arrives first in the
Disadv.
ready queue is firstly assigned the CPU.
• In case of a tie, process with smaller Convey Effect:
process id is executed first. • Consider processes with higher burst time
• It is always non-preemptive in nature. arrived before the processes with smaller
burst time.
• Then, smaller processes have to wait for a
Adv. long time for longer processes to release
• It is simple and easy to understand. the CPU.
• It can be easily implemented using
queue data structure.
• It does not lead to starvation.
ROLE PLAY (SRTF)
EXERCISE (FCFS)
ANS. AVG. TAT=29/5 AND
AVG. WT=16/5
SHORTEST JOB FIRST(SJF)
• Out of all the available processes, CPU is
assigned to the process having smallest
burst time.
• In case of a tie, it is broken by
FCFS Scheduling. SR
TF
• It is Non-Preemptive (NP) in nature.
P ) EM E ( P
(N PT - R
J F ) IVE
S
SHORTEST REMAINING TIME
FIRST(SRTF)
• SJF Scheduling can be used in both Disadv.
preemptive and non-preemptive mode. • It can not be implemented practically
• Preemptive mode of Shortest Job First is since burst time of the processes can
called as Shortest Remaining Time not be known in advance.
First (SRTF). • It leads to starvation for processes with
larger burst time.
Adv. • Priorities can not be set for the
• SRTF is optimal and guarantees the processes.
minimum average waiting time. • Processes with larger burst time have
• It provides a standard for other poor response time.
algorithms since no other algorithm
performs better than it.
EXAMPLE (SJF)
ANS. AVG. TAT=40 / 5 = 8 UNIT
AND AVG. WT= 24 / 5 = 4.8 UNIT
EXAMPLE(SRTF)
ANS. AVG. TAT=35 / 5 = 7 UNIT
AND AVG. WT= 19 / 5 = 3.8 UNIT
In the context of CPU scheduling, the shortest job
first (SJF) algorithm is optimal in terms of:

A) Maximizing CPU utilization


B) Minimizing average waiting time
C) Minimizing turnaround time for long processes
D) Maximizing throughput
ANS. B
B) Minimizing average waiting time
In the context of CPU scheduling, which of the following
statements is true regarding the shortest remaining time
first (SRTF) algorithm?

A) SRTF is a non-preemptive scheduling algorithm.

B) In SRTF, the process with the longest remaining time is given the CPU next.

C) SRTF is an optimal scheduling algorithm for minimizing average waiting time.

D) SRTF can lead to a convoy effect, where longer processes are delayed indefinitely.
ANS. C
C) SRTF is an optimal scheduling algorithm for minimizing average waiting time.
PRIORITY SCHEDULING
• Out of all the available processes, CPU Adv:
is assigned to the process having the • It considers the priority of the
highest priority. processes and allows the important
• In case of a tie, it is broken by processes to run first.
FCFS Scheduling. • Priority scheduling in preemptive mode
• Priority Scheduling can be used in both is best suited for real time operating
preemptive and non-preemptive mode. system.
• By default, lower the number means
higher the priority otherwise if Disadv.
mentioned in the question then follow
the higher number means higher • Processes with lesser priority may
priority. starve for CPU.
• There is no idea of response time and
waiting time.
Note 1:
• The waiting time for the process having the
highest priority will always be zero in

Importan
preemptive mode.
• The waiting time for the process having the
highest priority may not be zero in non-

t Notes-
preemptive mode.

Note 2:
• Priority scheduling in preemptive and non-
preemptive mode behaves exactly same under
following conditions-
• The arrival time of all the processes is same
EXAMPLE(PRIORITY)
ANS. AVG. TAT= 41 / 5 = 8.2 UNIT
AND AVG. WT= 26 / 5 = 5.2 UNIT
EXAMPLE (PRIORITY)
ANS. AVG. TAT= 38 / 5 = 7.6 UNIT
AND AVG. WT= 23 / 5 = 4.6 UNIT
Which of the following CPU scheduling algorithms
can cause the phenomenon known as "starvation"?

A) First-Come, First-Served (FCFS)


B) Shortest Job Next (SJN)
C) Round Robin (RR)
D) Priority Scheduling
ANS. D
D) Priority Scheduling

Priority Scheduling can lead to starvation, where lower-priority processes may


never get executed if there are always higher-priority processes arriving.
ROUND-ROBIN (RR)
SCHEDULING
• Round Robin Scheduling is FCFS • Adv.
Scheduling with preemptive mode.
• It gives the best performance in terms of
• There are two Queues: average response time.
• Ready Queue • It is best suited for time sharing system,
• Running Queue (Also called Gantt Chart) client server architecture and interactive
system.
• It is always preemptive in nature.
• CPU is assigned to the process on the
basis of FCFS for a fixed amount of time. Disadv.
• This fixed amount of time is called • It leads to starvation for processes with
as time quantum or time slice. larger burst time as they have to repeat
• After the time quantum expires, the the cycle many times.
running process is preempted and sent • Its performance heavily depends on time
to the ready queue. quantum.
• Then, the processor is assigned to the • Priorities can not be set for the
next arrived process. processes.
IMPORTANT NOTES (RR)
• Note-01:
• With decreasing value of time quantum, • Note-03:
• number of context switch increases
• Response time decreases
• With increasing value of time quantum, Round
• Chances of starvation decreases Robin Scheduling tends to become FCFS
Scheduling.
• Thus, smaller value of time quantum is better in • When time quantum tends to infinity, Round
terms of response time. Robin Scheduling becomes FCFS Scheduling.

• Note-02:

• Note-04:
• With increasing value of time quantum,
• Number of context switch decreases
• The performance of Round Robin scheduling
• Response time increases
heavily depends on the value of time
• Chances of starvation increases quantum.
• The value of time quantum should be such
• Thus, higher value of time quantum is better in that it is neither too big nor too small.
EXAMPLE(RR)
ANS. AVG. TAT=43 / 5 = 8.6 UNIT AND
AVG. WT= 29 / 5 = 5.8 UNIT
ANS. AVG. TAT=43 / 5 = 8.6 UNIT AND
AVG. WT= 29 / 5 = 5.8 UNIT
ANS. AVG. TAT=43 / 5 = 8.6 UNIT AND
AVG. WT= 29 / 5 = 5.8 UNIT
In the round robin scheduling algorithm, what primarily
determines the time a process is allowed to run before it is
swapped out?

a) Priority of the process


b) Size of the process
c) Time quantum
d) CPU speed
ANS.C
c) Time quantum
Explanation: The Round Robin scheduling algorithm is time-sliced, where each
process gets a fixed amount of CPU time called the time quantum. After the time
quantum expires, the process is swapped out and moved to the back of the queue
if it has not finished.
MULTI-LEVEL FEEDBACK
QUEUE (MLFQ)
A multilevel feedback queue (MLFQ)
is a CPU scheduling algorithm that
uses multiple queues with varying
priorities to manage process
execution.
In a multi-level feedback queue scheduling
algorithm, how does a process move between the
queues?

A) Based on the priority of the process.


B) Based on the size of the process.
C) Based on the CPU burst time of the process.
D) Based on the I/O requirements of the process.
ANS.C
C) Based on the CPU burst time of the process.
Explanation:
In a Multi-Level Feedback Queue, processes can move between queues based on
their behavior and characteristics, like CPU burst time. If a process uses too much
CPU time, it is moved to a lower-priority queue. If a process waits too long in a
lower-priority queue, it may be moved to a higher-priority queue to prevent
starvation.
DISPATCHER
REAL TIME SCHEDULING

• Real time scheduling is of two types: • The foremost is that the processes are
• Soft Real-Time scheduling which considered periodic i.e., the process
does not guarantee when when a will repeat itself after a fixed period of
critical real-time process will be time. The period of a process is
scheduled.(Algorithm: Rate Monotonic) denoted by p. The next characteristic is
the processing time t i.e., the time for
• Hard Real-Time scheduling in which which the process requires the CPU
the process must be scheduled before within each period. In other words
the deadline.(Algorithm: Earliest Dead processing time refers to the burst
Line(EDL)) time. The final characteristic is the
deadline d, i.e., the time before which
the process must be serviced.
TYPES OF RT SCHEDULING

• In rate-monotonic scheduling • In earlier deadline first scheduling


algorithm a static priority policy with algorithm assigns priority to the
preemption is used. Whenever a high process based on the deadline. Earlier
priority process arrives it will preempt a the deadline, higher is the priority.
lower priority process. Every process Thus, the priorities keep on changing in
gets the priority according to its period. this scheduling.
Lower the period higher is the priority.
Also, the processing time remains the
same in each period.
Which of the following is NOT a characteristic of
real-time scheduling algorithms in operating
systems?

A) Predictability
B) Deadline adherence
C) Preemptive scheduling
D) Round-robin fairness
ANS.D
D) Round-robin fairness
Explanation: Real-time scheduling focuses on predictability, deadline adherence,
and preemptive scheduling to ensure critical tasks meet their deadlines. Round-
robin fairness is not a priority in real-time systems, as it might not guarantee that
high-priority or time-sensitive tasks are completed on time.
• In multi-processor system, there are multiple CPUs.
• Load Balancing: The load is distributed among these
available processors.
• But in multi-processor system, it is quite complex.

Multi-
Types:
Processor • Asymmetric Multiprocessing: All scheduling decisions,
Scheduling I/O processing, and other system activities handled by a
single processor- master server.
• Local Ready Queue
• Symmetric Multiprocessing (SMP): Each processor is
self-scheduling. All processes may be in a common
ready queue, or each processor may have its own
private queue of ready processes.
• Global Ready Queue
• Avoid migration of processes from one processor to
another and instead attempt to keep a process

Process
running on the same processor. This is known as
processor affinity.

Affinity
• i.e. a process has an affinity for the processor on
which it is currently running.

and its
Types:
• Soft affinity: It is possible for a process to migrate

types
between processors.(migration possible)
• Hard affinity: Allowing a process to specify that it is
not to migrate to other processors. .(migration strictly
not possible)
• A thread is the smallest unit of execution which has its own
thread ID, program counter, register set and stack. All the
threads that belong to the same process share the code,
data section and other resources like open files belonging
to the process. So, remember thread is a part of the
Thread process. A thread can not exist without a process.

SchedulinTypes:
g • User threads are supported above the kernel and
managed without kernel support whereas Kernel
threads are supported and managed directly by OS.
REFERENCES
• OPERATING SYSTEM CONCEPTS by ABRAHAM
SILBERSCHATZ, PETER B. GALVIN, GERG GAGNE, WILEY
• DESIGN OF THE UNIX OPERATING SYSTEM by MAURICE
J. BACH, Pearson Education India
• REAL-TIME SYSTEMS by JANE W. S. LIU, Pearson
Education India
• https://www.javatpoint.com/os-scheduling-algorithms
• https://www.idconline.com/technical_references/pdfs/inf
ormation_technology/Types_of_Scheduling.pdf
REFERENCES
• https://www.gatevidyalay.com/first-come-first-serve-cp
u-scheduling/
• https://www.gatevidyalay.com/sjf-scheduling-srtf-cpu-sc
heduling/
• https://www.gatevidyalay.com/round-robin-round-robin-
scheduling-examples/
• https://www.javatpoint.com/os-fcfs-scheduling
THANK YOU

You might also like