SlideShare a Scribd company logo
1 of 59
Operating Systems
Lecture#4
Scheduler and its types,
Scheduling Algorithms
Week#2,Aug,23rd
Scheduling and Scheduler
Definition: When more than one process is runnable,
the operating system must decide which one run first.
The part of the operating system concerned with this
decision is called the scheduler, and algorithm it uses
is called the scheduling algorithm.
Scheduling and Scheduler
Types of Scheduler
Types of Scheduler
Primary Scheduler Secondary Scheduler
Primary Scheduler
1. Runs threads with the highest priority.
2. It then compares their priority and assigns
resources to them, depending on their priority.
3. Threads with the highest priority will be executed
for the current time slice.
4. With two or more threads with the same priority,
they are put on a stack to allow each run on a given
time slot.
Scheduling and Scheduler: Primary
Scheduler
Secondary Scheduler
1. It is responsible for increasing the priority of non-
executing threads.
2. It is important that those low-priority threads are
given a chance to run on the operating system and
this is the function of this type of scheduler.
Scheduling and Scheduler: Secondary
Scheduler
• How scheduler knows the current status of each
process?
• We need to define states of processes so that
scheduler can respond to each process
Scheduling and Scheduler
FOUR STATES OF PROCESS
• New
• Ready
• Running
• Waiting
• Terminated
FOUR STATES OF PROCESS
• Ready: The process is in the main memory(RAM) and
available for execution.
• Blocked: The process is in the main memory and awaiting
response.
• Blocked/Suspend: The process is in secondary
memory(hard disk) and awaiting response.
• Ready/Suspend: The process is in the secondary
memory(hard disk) but is available for execution as soon as
it is loaded into the main memory.
FOUR STATES OF PROCESS
• These four states helps the scheduler to respond
to each process according to its current state so
that process can be handled efficiently.
FOUR STATES OF PROCESS
Scheduling Goals
• Fairness: Scheduler makes sure that each process
gets its fair share of the CPU.
• Efficiency: Scheduler must keep the CPU busy 100
percent of the time.
• Waiting time: Scheduler should minimize the
waiting time for job.
• Turnaround: Scheduler should minimize the time
of how long processes must wait for output.
• Throughput: Scheduler should maximize the
number of jobs processed per hour.
Scheduling Goals
CPU Scheduling
• Example (Enter the bank and process a transaction)
• Arrival Time: The time at which the process enters
the ready queue or state
• Burst Time: Time required by a process to get
executed on CPU
• Completion Time: Time at which the process
completes its execution
CPU Scheduling
• Turn Around Time; {Completion Time – Arrival
Time}
• Waiting Time: {Turn Around Time – Burst Time}
• Response Time: {(The time at which a process gets
CPU first time) – (Arrival Time)}
CPU Scheduling
Scheduling Algorithms
Two types of scheduling algorithms:
Non-preemptive Scheduling
• A scheduling is non-preemptive if, once a process has been
given to the CPU, it cannot be taken away.
• Example: 5 students need to ask 4 questions each
Preemptive and Non- Preemptive Scheduling
Algorithms
Two types of scheduling algorithms:
Preemptive Scheduling
• A scheduling is preemptive if, once a process has been
given to the CPU, it can be taken away.
• Example: 5 students need to ask 4 questions each
• We shall take turns
Preemptive and Non- Preemptive Scheduling
Algorithms
Reasons for Preemption
• Time Quantum
• Example: Teacher gives time to each student for question
• Priority
• Example: Some high priority student may ask question
• Shortest job
• Example: Student asking short questions
Preemptive and Non- Preemptive Scheduling
Algorithms
1. FCFS Scheduling
2. SJF Scheduling
3. SRTN Scheduling
4. Priority Scheduling
5. Round Robin (RR) Scheduling
Scheduling Algorithms
FCFS(First Come First Serve)
Scheduling algorithm
• It is Non-preemptive Algorithm
• Follows First-In-First-Out (FIFO) rule
• Run-to-Completion
• Run-Until-Finish
FCFS Scheduling algorithm
• Runs the processes in the order they arrive.
• Removes a process from the processor only if it is in block
state or terminates.
• Advantage: Good for long processes when they finally
get on.
• Disadvantage: Bad for short processes if they are behind
a long process.
FCFS Scheduling algorithm
FCFS Scheduling algorithm
Process
No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 0 2 2 2 0 0
P2 1 2 4 3 1 1
P3 5 3 8 3 0 0
P4 6 4 12 6 2 2
FCFS Scheduling algorithm
P1 P2 P3 P4
0 2 4 5 8 12
SJF(Shortest Job First) Scheduling
algorithm
• Shortest-Job-First (SJF) is a non-preemptive scheduling
algorithm.
• In this algorithm the process which takes the shortest
time to complete is run first.
• It thus completes the processes that need a short time to
be served and hence processes can be efficiently handled.
SJF Scheduling algorithm
• P3 has shortest time unit of 2 and hence is scheduled
first.
• Process with same time units can be placed one after
other.
SJF Scheduling algorithm
Process
No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 1 3 6 5 2 2
P2 2 4 10 8 4 4
P3 1 2 3 2 0 0
P4 4 4 14 10 6 6
SJF Scheduling algorithm
Process
No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 1 3 6 5 2 2
P2 2 4 10 8 4 4
P3 1 2 3 2 0 0
P4 4 4 14 10 6 6
SJF Scheduling algorithm
P3 P1 P2 P4
0 1 3 6 10 14
SJF Scheduling algorithm
SRTN(Shortest Remaining Time Next)
Scheduling algorithm
1. It is preemptive version of SJF.
2. Short job is given immediate preference to a running
longer job.
3. The scheduler always chooses the process whose
remaining run time is the shortest.
4. Must estimate expected remaining processing time
5. If the new job needs less time to finish than the current
process, the current SJF process is suspended and the new
job is finished by SRTN.
SRTN Scheduling algorithm
Process
No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 0 5 9 9 4 0
P2 1 3 4 3 0 0
P3 2 4 13 11 7 7
P4 4 1 5 1 0 0
SRTN Scheduling algorithm
Process
No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 0 5 9 9 4 0
P2 1 3 4 3 0 0
P3 2 4 13 11 7 7
P4 4 1 5 1 0 0
SRTN Scheduling algorithm
0 1 2 3 4 5 6 7 8 9 10 11 12 13
P1 P2 P2 P2 P4 P1 P1 P1 P1 P3 P3 P3 P3
SRTN Scheduling algorithm
Priority Scheduling algorithm
• Each process is assigned a priority, and priority based
process is allowed to run first.
• Equal-Priority processes are scheduled in FCFS order.
• The shortest-Job-First (SJF) algorithm is a special case of
general priority scheduling algorithm.
Priority Scheduling algorithm
Priority Scheduling algorithm
• Examples of Internal priorities are
– Time limits.
– Memory requirements.
– File requirements,
for example, number of open files.
– CPU Vs I/O requirements.
Priority Scheduling algorithm
• Externally defined priorities are set by criteria that are
external to operating system such as
– The importance of process.
– Type or amount of funds being paid for computer use.
Priority Scheduling algorithm
• Priority scheduling can be either preemptive or non
preemptive
– A preemptive priority algorithm will preempt the CPU if the
priority of the newly arrival process is higher than the priority of
the currently running process.
– A non-preemptive priority algorithm will simply put the new
process at the head of the ready queue.
Priority Scheduling algorithm
• A major problem with priority scheduling is indefinite
blocking or starvation.
• A solution to the problem of indefinite blockage of the low-
priority process is aging.
• Aging is a technique of gradually increasing the priority of
processes that wait in the system for a long period of time.
Priority Scheduling algorithm
Prio
rity
Proc
ess
No.
Arriva
l Time
Bur
st
Tim
e
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
10 P1 0 5 12 12 7 0
20 P2 1 4 8 7 3 0
30 P3 2 2 4 2 0 0
40 P4 4 1 5 1 0 0
Priority Scheduling algorithm
Prio
rity
Proc
ess
No.
Arriva
l Time
Bur
st
Tim
e
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
10 P1 0 5 12 12 7 0
20 P2 1 4 8 7 3 0
30 P3 2 2 4 2 0 0
40 P4 4 1 5 1 0 0
Priority Scheduling algorithm
0 1 2 3 4 5 6 7 8 9 10 11 12
P1 P2 P3 P3 P4 P2 P2 P2 P1 P1 P1 P1
Round Robin Scheduling algorithm
• Round-robin (RR) is one of the algorithms employed
by process and network schedulers in computing.
• In this algorithms time units or slices are allotted to process.
• This time unit is also called quanta or quantum.
• Equal time slices are allotted to each process in form of a
queue.
• Once the time or quantum has passed for a particular
process, the process is sent to the end of the queue and next
one is handled. This process is called context switching.
Round Robin Scheduling algorithm
• Here q is quantum or time slice.
Round Robin Scheduling algorithm
Advantage of RR Algorithm: It is fair because each process
gets equal share of CPU.
Disadvantage of RR Algorithm: If time slice is too short for
any process, the CPU will get overloaded and it will also cause
delay in process handling.
Round Robin Scheduling algorithm
• In a computer for example, the user starts three
applications, Email, a web browser, and a word
processor.
• These applications are loaded into system memory as
processes and each is allowed to run without the user
considering which applications are running in the
background.
Application of RR Scheduling algorithm
Proces
s No.
Arrival
Time
Burst
Time
Compl
etion
Time
Turnar
ound
Time
Waitin
g Time
Respon
se Time
P1 0 5 12 12 7 0
P2 1 4 11 10 6 1
P3 2 2 6 4 2 2
P4 4 1 9 5 4 4
Round Robin Scheduling algorithm
0 2 4 6 8 9 11 12
P1 P2 P3 P1 P4 P2 P1
P1 P2 P3 P1 P4 P2 P1
Ready Queue
Running Queue
DEADLOCK
• In this section we will now study some important
concepts related to deadlocks.
• This is also a major problem that an O.S has to solve.
• Recall how a deadlock occurs.
• A deadlock is a situation in which two computer programs
sharing the same resource are preventing each other from
accessing the resource, resulting in both programs ceasing
to function.
DEADLOCK
RESOURCE
 A resource is anything that can be used by
only a single process at any instant of time.
A resource can be the hardware device or a
piece of information.
For example a printer is a hardware resource.
RESOURCE
TYPES OF RESOURCE
Types of Resources
Preemptable
Resource
Non-Preemptable
Resource
Preemptable Resource :
• It is one that can be taken away from the process owing
it.
• Main memory(RAM) is an example of preemptable
resource.
Non-Preemptable Resource:
• It is one that cannot be taken away from the process
owing it.
• CD-ROM, Tape Drives, Printers etc are the examples of
non-preemptable resources.
RESOURCE
programming .pptx

More Related Content

Similar to programming .pptx

In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .nathansel1
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdfKp Sharma
 
CPU scheduling
CPU schedulingCPU scheduling
CPU schedulingAmir Khan
 
LM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processesLM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processesmanideepakc
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Shreya Kumar
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptxDivyaKS18
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptxyashu23
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithmsShubham Sharma
 
ch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfSonaliAjankar
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithmsPaurav Shah
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCKVicky Kumar
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingVaibhav Khanna
 

Similar to programming .pptx (20)

Lecture 4 process cpu scheduling
Lecture 4   process cpu schedulingLecture 4   process cpu scheduling
Lecture 4 process cpu scheduling
 
CPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdfCPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdf
 
In computing, scheduling is the action .
In computing, scheduling is the action .In computing, scheduling is the action .
In computing, scheduling is the action .
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
OS Process Chapter 3.pdf
OS Process Chapter 3.pdfOS Process Chapter 3.pdf
OS Process Chapter 3.pdf
 
CPU scheduling
CPU schedulingCPU scheduling
CPU scheduling
 
LM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processesLM10,11,12 - CPU SCHEDULING algorithms and its processes
LM10,11,12 - CPU SCHEDULING algorithms and its processes
 
Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.Process scheduling in Light weight weight and Heavy weight processes.
Process scheduling in Light weight weight and Heavy weight processes.
 
PROCESS.pptx
PROCESS.pptxPROCESS.pptx
PROCESS.pptx
 
CPU Scheduling.pptx
CPU Scheduling.pptxCPU Scheduling.pptx
CPU Scheduling.pptx
 
Process scheduling algorithms
Process scheduling algorithmsProcess scheduling algorithms
Process scheduling algorithms
 
Scheduling
SchedulingScheduling
Scheduling
 
ch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdfch5_CPU Scheduling_part1.pdf
ch5_CPU Scheduling_part1.pdf
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
 
CPU Scheduling
CPU SchedulingCPU Scheduling
CPU Scheduling
 
Osy ppt - Copy.pptx
Osy ppt - Copy.pptxOsy ppt - Copy.pptx
Osy ppt - Copy.pptx
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCK
 
CPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdfCPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdf
 
Section05 scheduling
Section05 schedulingSection05 scheduling
Section05 scheduling
 
Operating system 28 fundamental of scheduling
Operating system 28 fundamental of schedulingOperating system 28 fundamental of scheduling
Operating system 28 fundamental of scheduling
 

More from SHUJEHASSAN

computer generation .pptx
computer generation .pptxcomputer generation .pptx
computer generation .pptxSHUJEHASSAN
 
mini computer .pptx
mini computer .pptxmini computer .pptx
mini computer .pptxSHUJEHASSAN
 
super computer .pptx
super computer .pptxsuper computer .pptx
super computer .pptxSHUJEHASSAN
 
computer science .pptx
computer science .pptxcomputer science .pptx
computer science .pptxSHUJEHASSAN
 
introduce computer .pptx
introduce computer .pptxintroduce computer .pptx
introduce computer .pptxSHUJEHASSAN
 
ethic of daily life .pptx
ethic of daily life .pptxethic of daily life .pptx
ethic of daily life .pptxSHUJEHASSAN
 
FundamentalsofComputerStudies.pdf
FundamentalsofComputerStudies.pdfFundamentalsofComputerStudies.pdf
FundamentalsofComputerStudies.pdfSHUJEHASSAN
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdfSHUJEHASSAN
 
gestalt-principles-keli-dirisio.pdf
gestalt-principles-keli-dirisio.pdfgestalt-principles-keli-dirisio.pdf
gestalt-principles-keli-dirisio.pdfSHUJEHASSAN
 

More from SHUJEHASSAN (12)

computer generation .pptx
computer generation .pptxcomputer generation .pptx
computer generation .pptx
 
mini computer .pptx
mini computer .pptxmini computer .pptx
mini computer .pptx
 
super computer .pptx
super computer .pptxsuper computer .pptx
super computer .pptx
 
computer science .pptx
computer science .pptxcomputer science .pptx
computer science .pptx
 
introduce computer .pptx
introduce computer .pptxintroduce computer .pptx
introduce computer .pptx
 
AI .pptx
AI .pptxAI .pptx
AI .pptx
 
ethic of daily life .pptx
ethic of daily life .pptxethic of daily life .pptx
ethic of daily life .pptx
 
FundamentalsofComputerStudies.pdf
FundamentalsofComputerStudies.pdfFundamentalsofComputerStudies.pdf
FundamentalsofComputerStudies.pdf
 
popl04.ppt
popl04.pptpopl04.ppt
popl04.ppt
 
1585397407.pdf
1585397407.pdf1585397407.pdf
1585397407.pdf
 
12IRGeneration.pdf
12IRGeneration.pdf12IRGeneration.pdf
12IRGeneration.pdf
 
gestalt-principles-keli-dirisio.pdf
gestalt-principles-keli-dirisio.pdfgestalt-principles-keli-dirisio.pdf
gestalt-principles-keli-dirisio.pdf
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

programming .pptx

  • 1. Operating Systems Lecture#4 Scheduler and its types, Scheduling Algorithms Week#2,Aug,23rd
  • 3. Definition: When more than one process is runnable, the operating system must decide which one run first. The part of the operating system concerned with this decision is called the scheduler, and algorithm it uses is called the scheduling algorithm. Scheduling and Scheduler
  • 4. Types of Scheduler Types of Scheduler Primary Scheduler Secondary Scheduler
  • 5. Primary Scheduler 1. Runs threads with the highest priority. 2. It then compares their priority and assigns resources to them, depending on their priority. 3. Threads with the highest priority will be executed for the current time slice. 4. With two or more threads with the same priority, they are put on a stack to allow each run on a given time slot. Scheduling and Scheduler: Primary Scheduler
  • 6. Secondary Scheduler 1. It is responsible for increasing the priority of non- executing threads. 2. It is important that those low-priority threads are given a chance to run on the operating system and this is the function of this type of scheduler. Scheduling and Scheduler: Secondary Scheduler
  • 7. • How scheduler knows the current status of each process? • We need to define states of processes so that scheduler can respond to each process Scheduling and Scheduler
  • 8. FOUR STATES OF PROCESS
  • 9. • New • Ready • Running • Waiting • Terminated FOUR STATES OF PROCESS
  • 10. • Ready: The process is in the main memory(RAM) and available for execution. • Blocked: The process is in the main memory and awaiting response. • Blocked/Suspend: The process is in secondary memory(hard disk) and awaiting response. • Ready/Suspend: The process is in the secondary memory(hard disk) but is available for execution as soon as it is loaded into the main memory. FOUR STATES OF PROCESS
  • 11. • These four states helps the scheduler to respond to each process according to its current state so that process can be handled efficiently. FOUR STATES OF PROCESS
  • 13. • Fairness: Scheduler makes sure that each process gets its fair share of the CPU. • Efficiency: Scheduler must keep the CPU busy 100 percent of the time. • Waiting time: Scheduler should minimize the waiting time for job. • Turnaround: Scheduler should minimize the time of how long processes must wait for output. • Throughput: Scheduler should maximize the number of jobs processed per hour. Scheduling Goals
  • 15. • Example (Enter the bank and process a transaction) • Arrival Time: The time at which the process enters the ready queue or state • Burst Time: Time required by a process to get executed on CPU • Completion Time: Time at which the process completes its execution CPU Scheduling
  • 16. • Turn Around Time; {Completion Time – Arrival Time} • Waiting Time: {Turn Around Time – Burst Time} • Response Time: {(The time at which a process gets CPU first time) – (Arrival Time)} CPU Scheduling
  • 18. Two types of scheduling algorithms: Non-preemptive Scheduling • A scheduling is non-preemptive if, once a process has been given to the CPU, it cannot be taken away. • Example: 5 students need to ask 4 questions each Preemptive and Non- Preemptive Scheduling Algorithms
  • 19. Two types of scheduling algorithms: Preemptive Scheduling • A scheduling is preemptive if, once a process has been given to the CPU, it can be taken away. • Example: 5 students need to ask 4 questions each • We shall take turns Preemptive and Non- Preemptive Scheduling Algorithms
  • 20. Reasons for Preemption • Time Quantum • Example: Teacher gives time to each student for question • Priority • Example: Some high priority student may ask question • Shortest job • Example: Student asking short questions Preemptive and Non- Preemptive Scheduling Algorithms
  • 21. 1. FCFS Scheduling 2. SJF Scheduling 3. SRTN Scheduling 4. Priority Scheduling 5. Round Robin (RR) Scheduling Scheduling Algorithms
  • 22. FCFS(First Come First Serve) Scheduling algorithm
  • 23. • It is Non-preemptive Algorithm • Follows First-In-First-Out (FIFO) rule • Run-to-Completion • Run-Until-Finish FCFS Scheduling algorithm
  • 24. • Runs the processes in the order they arrive. • Removes a process from the processor only if it is in block state or terminates. • Advantage: Good for long processes when they finally get on. • Disadvantage: Bad for short processes if they are behind a long process. FCFS Scheduling algorithm
  • 26. Process No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 0 2 2 2 0 0 P2 1 2 4 3 1 1 P3 5 3 8 3 0 0 P4 6 4 12 6 2 2 FCFS Scheduling algorithm P1 P2 P3 P4 0 2 4 5 8 12
  • 27. SJF(Shortest Job First) Scheduling algorithm
  • 28. • Shortest-Job-First (SJF) is a non-preemptive scheduling algorithm. • In this algorithm the process which takes the shortest time to complete is run first. • It thus completes the processes that need a short time to be served and hence processes can be efficiently handled. SJF Scheduling algorithm
  • 29. • P3 has shortest time unit of 2 and hence is scheduled first. • Process with same time units can be placed one after other. SJF Scheduling algorithm
  • 30. Process No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 1 3 6 5 2 2 P2 2 4 10 8 4 4 P3 1 2 3 2 0 0 P4 4 4 14 10 6 6 SJF Scheduling algorithm
  • 31. Process No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 1 3 6 5 2 2 P2 2 4 10 8 4 4 P3 1 2 3 2 0 0 P4 4 4 14 10 6 6 SJF Scheduling algorithm P3 P1 P2 P4 0 1 3 6 10 14
  • 33. SRTN(Shortest Remaining Time Next) Scheduling algorithm
  • 34. 1. It is preemptive version of SJF. 2. Short job is given immediate preference to a running longer job. 3. The scheduler always chooses the process whose remaining run time is the shortest. 4. Must estimate expected remaining processing time 5. If the new job needs less time to finish than the current process, the current SJF process is suspended and the new job is finished by SRTN. SRTN Scheduling algorithm
  • 35. Process No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 0 5 9 9 4 0 P2 1 3 4 3 0 0 P3 2 4 13 11 7 7 P4 4 1 5 1 0 0 SRTN Scheduling algorithm
  • 36. Process No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 0 5 9 9 4 0 P2 1 3 4 3 0 0 P3 2 4 13 11 7 7 P4 4 1 5 1 0 0 SRTN Scheduling algorithm 0 1 2 3 4 5 6 7 8 9 10 11 12 13 P1 P2 P2 P2 P4 P1 P1 P1 P1 P3 P3 P3 P3
  • 39. • Each process is assigned a priority, and priority based process is allowed to run first. • Equal-Priority processes are scheduled in FCFS order. • The shortest-Job-First (SJF) algorithm is a special case of general priority scheduling algorithm. Priority Scheduling algorithm
  • 41. • Examples of Internal priorities are – Time limits. – Memory requirements. – File requirements, for example, number of open files. – CPU Vs I/O requirements. Priority Scheduling algorithm
  • 42. • Externally defined priorities are set by criteria that are external to operating system such as – The importance of process. – Type or amount of funds being paid for computer use. Priority Scheduling algorithm
  • 43. • Priority scheduling can be either preemptive or non preemptive – A preemptive priority algorithm will preempt the CPU if the priority of the newly arrival process is higher than the priority of the currently running process. – A non-preemptive priority algorithm will simply put the new process at the head of the ready queue. Priority Scheduling algorithm
  • 44. • A major problem with priority scheduling is indefinite blocking or starvation. • A solution to the problem of indefinite blockage of the low- priority process is aging. • Aging is a technique of gradually increasing the priority of processes that wait in the system for a long period of time. Priority Scheduling algorithm
  • 45. Prio rity Proc ess No. Arriva l Time Bur st Tim e Compl etion Time Turnar ound Time Waitin g Time Respon se Time 10 P1 0 5 12 12 7 0 20 P2 1 4 8 7 3 0 30 P3 2 2 4 2 0 0 40 P4 4 1 5 1 0 0 Priority Scheduling algorithm
  • 46. Prio rity Proc ess No. Arriva l Time Bur st Tim e Compl etion Time Turnar ound Time Waitin g Time Respon se Time 10 P1 0 5 12 12 7 0 20 P2 1 4 8 7 3 0 30 P3 2 2 4 2 0 0 40 P4 4 1 5 1 0 0 Priority Scheduling algorithm 0 1 2 3 4 5 6 7 8 9 10 11 12 P1 P2 P3 P3 P4 P2 P2 P2 P1 P1 P1 P1
  • 48. • Round-robin (RR) is one of the algorithms employed by process and network schedulers in computing. • In this algorithms time units or slices are allotted to process. • This time unit is also called quanta or quantum. • Equal time slices are allotted to each process in form of a queue. • Once the time or quantum has passed for a particular process, the process is sent to the end of the queue and next one is handled. This process is called context switching. Round Robin Scheduling algorithm
  • 49. • Here q is quantum or time slice. Round Robin Scheduling algorithm
  • 50. Advantage of RR Algorithm: It is fair because each process gets equal share of CPU. Disadvantage of RR Algorithm: If time slice is too short for any process, the CPU will get overloaded and it will also cause delay in process handling. Round Robin Scheduling algorithm
  • 51. • In a computer for example, the user starts three applications, Email, a web browser, and a word processor. • These applications are loaded into system memory as processes and each is allowed to run without the user considering which applications are running in the background. Application of RR Scheduling algorithm
  • 52. Proces s No. Arrival Time Burst Time Compl etion Time Turnar ound Time Waitin g Time Respon se Time P1 0 5 12 12 7 0 P2 1 4 11 10 6 1 P3 2 2 6 4 2 2 P4 4 1 9 5 4 4 Round Robin Scheduling algorithm 0 2 4 6 8 9 11 12 P1 P2 P3 P1 P4 P2 P1 P1 P2 P3 P1 P4 P2 P1 Ready Queue Running Queue
  • 54. • In this section we will now study some important concepts related to deadlocks. • This is also a major problem that an O.S has to solve. • Recall how a deadlock occurs. • A deadlock is a situation in which two computer programs sharing the same resource are preventing each other from accessing the resource, resulting in both programs ceasing to function. DEADLOCK
  • 56.  A resource is anything that can be used by only a single process at any instant of time. A resource can be the hardware device or a piece of information. For example a printer is a hardware resource. RESOURCE
  • 57. TYPES OF RESOURCE Types of Resources Preemptable Resource Non-Preemptable Resource
  • 58. Preemptable Resource : • It is one that can be taken away from the process owing it. • Main memory(RAM) is an example of preemptable resource. Non-Preemptable Resource: • It is one that cannot be taken away from the process owing it. • CD-ROM, Tape Drives, Printers etc are the examples of non-preemptable resources. RESOURCE