SlideShare a Scribd company logo
1 of 23
DEADLOCK PREVENTION &
RECOVERY
I am S.RAJAPRIYA
I am here because I love to give a fright.
You can find me at rajapriya@vvvcollege.org
DEADLOCK
2
✘ The Deadlock Problem
✘ System Model
✘ Deadlock Characterization
✘ Methods for Handling
Deadlocks
✘ Deadlock Prevention
✘ Deadlock Avoidance
✘ Deadlock Detection
✘ Recovery from Deadlock
The Deadlock Problem
A set of blocked processes each holding a resource and
waiting to acquire a resource held by another process in
the set
Example
System has 2 disk drives
P1 and P2 each hold one disk drive and each needs
another one
3
“A Deadlock is a permanent blocking of a
set of threads”
4
SYSTEM MODEL
✘ Resources typesR1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
✘ Each resource type Ri has Wi instances.
✘ Each process utilizes a resource as follows:
✗ request
✗ use
✗ release
5
Mutual exclusion :
only one process at a time can
use a resource. If another process request
that resource, the requesting process must
be delayed until the resource has been
released
Hold and wait :
a process holding at least one
resource is waiting to acquire additional
resources held by other processes
Deadlock Characterization
No preemption :
a resource can be released only
voluntarily by the process holding it, after
that process has completed its task.
Circular wait :
there exists a set {P0, P1, …, P0}
of waiting processes such that P0 is
waiting for a resource that is held by P1,
P1 is waiting for a resource that is held by
P2, …, Pn–1 is waiting for a resource that is
held by
Pn, and P0 is waiting for a resource that is
held by P0.
6
RESOURCE ALLOCATION GRAPH
Deadlock can be described more precisely in terms of a directed
graph called a system resource allocation graph.
A set of vertices V and a set of edges E.
V is partitioned into two types:
• P = {P1, P2, …, Pn}, the set consisting of all the processes in the
system
• R = {R1, R2, …, Rm}, the set consisting of all resource types in the
system
• request edge – directed edge P1  Rj
• assignment edge – directed edge Rj  Pi
Example
7
Resource-Allocation Graph
✘ Pictorially, we represent
✘ Process
✘ Resource Type with 4 instances
✘ Pi requests instance of Rj
✘ Pi is holding an instance of Rj
8
Pi
Pi
Example of a Resource Allocation Graph
• The sets P,R,E:
o P={p1,p2,p3}
o R={R1,R2,R3,R4}
o E={P1->R1,P2->R3,R1->P2,
R2->P2,R2->P1,R3->P3}
9
Resource Allocation Graph with Deadlock
• Suppose that process P3 request an
instance of resource type R3.
• Since no resource is currently
available, a request edge P3->R2 is
added to the graph.
• At this point two cycles exist in the
system:
✘ P1->R1->P2->R3->P3->R2->P1
✘ P2->R3->P3->R2->P2
• Processes P1,P2,P3 are deadlocked.
10
Graph with a Cycle but No Deadlock
• In this example we also have a
cycle
✘ P1->R1->P3->R2->P1
• However, there is no cycle.
• Observe that process P4 may
release its resource R2.That
resource can then be allocated to
P3,breaking the cycle.
11
✘ If graph contains no cycles  no deadlock
✘ If graph contains a cycle 
✗ if only one instance per resource type, then deadlock
✗ if several instances per resource type, possibility of
deadlock
12
DEADLOCK PREVENTION
✘ By ensuring that at least one of these conditions cannot hold,
We can prevent the occurrence of a deadlock
13
Eliminate Mutual Exclusion –
not required for sharable
resources, must hold for non-sharable
resources. For example, a printer cannot
be shared by several processes. Read
only files are good example of sharable
resource
Eliminate Hold and Wait –
must guarantee that
whenever a process requests a
resource, it does not hold any other
resources.
Deadlock Prevention
✗ Allocate all required resources to the
process before the start of its
execution, this way hold and wait
condition is eliminated but it will
lead to low device utilization.
✗ For example, if a process requires
printer at a later time and we have
allocated printer before the start of
its execution printer will remain
blocked till it has completed its
execution.
✗ The process will make a new
request for resources after releasing
the current set of resources. This
solution may lead to starvation.
14
Eliminate No Preemption –
✗ If a process that is holding
some resources requests
another resource that cannot
be immediately allocated to it,
then all resources currently
being held are released.
✗ Preempted resources are
added to the list of resources
for which the process is
waiting.
Deadlock Prevention
✘ Process will be restarted
only when it can regain its
old resources, as well as the
new ones that it is
requesting.
15
Deadlock Prevention
Eliminate Circular Wait –
• Each resource will be assigned
with a numerical number. A
process can request the
resources increasing/decreasing
order of numbering.
• For Example, if P1 process is
allocated R5 resources, now next
time if P1 ask for R4, R3 lesser than
R5 such request will not be granted,
only request for resources more
than R5 will be granted.
16
A picture is worth a thousand words
17
Safe State!When a process requests an available resource, system must decide if
immediate allocation leaves the system in a safe state.
System is in safe state if there exists a safe sequence of all processes.
Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi
can still request can be satisfied by currently available resources
+ resources held by all the Pj, with j<I.
✗ If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished.
✗ When Pj is finished, Pi can obtain needed resources, execute,
return allocated resources, and terminate.
✗ When Pi terminates, Pi+1 can obtain its needed resources, and so
on.
18
19
Safe, Unsafe and Deadlock State
Place your screenshot here
Recovery from Deadlock
20
Process Termination
Resource Preemption
Process Termination
Abort all deadlocked
processes
Abort one
process at a
time until the
deadlock
cycle is
eliminated
In which
order should
we choose to
abort?
21
Resource Preemption
Selecting a victim
Starvation –
same process
may always be
picked as victim,
include number of
rollback in cost
factor
Rollback – return
to some safe
state, restart
process for that
state.
22
Thankyou
23

More Related Content

Similar to Deadlock (20)

Os unit 4
Os unit 4Os unit 4
Os unit 4
 
deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
OS deadlock.pptx
OS deadlock.pptxOS deadlock.pptx
OS deadlock.pptx
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Ch7 deadlocks
Ch7   deadlocksCh7   deadlocks
Ch7 deadlocks
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Os5
Os5Os5
Os5
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
Ice
IceIce
Ice
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 

More from Rajapriya82

Applications of IoTs in Home,City,Health
Applications of IoTs in Home,City,HealthApplications of IoTs in Home,City,Health
Applications of IoTs in Home,City,HealthRajapriya82
 
MD5 ALGORITHM.pptx
MD5 ALGORITHM.pptxMD5 ALGORITHM.pptx
MD5 ALGORITHM.pptxRajapriya82
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptxRajapriya82
 
SHA 1 Algorithm.ppt
SHA 1 Algorithm.pptSHA 1 Algorithm.ppt
SHA 1 Algorithm.pptRajapriya82
 
File System Implementation.pptx
File System Implementation.pptxFile System Implementation.pptx
File System Implementation.pptxRajapriya82
 
Consensus Algorithms.pptx
Consensus Algorithms.pptxConsensus Algorithms.pptx
Consensus Algorithms.pptxRajapriya82
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanismsRajapriya82
 
Wireless transmission
Wireless transmissionWireless transmission
Wireless transmissionRajapriya82
 
Guided Transmission Media
Guided  Transmission MediaGuided  Transmission Media
Guided Transmission MediaRajapriya82
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical dataRajapriya82
 

More from Rajapriya82 (13)

Applications of IoTs in Home,City,Health
Applications of IoTs in Home,City,HealthApplications of IoTs in Home,City,Health
Applications of IoTs in Home,City,Health
 
MD5 ALGORITHM.pptx
MD5 ALGORITHM.pptxMD5 ALGORITHM.pptx
MD5 ALGORITHM.pptx
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
SHA 1 Algorithm.ppt
SHA 1 Algorithm.pptSHA 1 Algorithm.ppt
SHA 1 Algorithm.ppt
 
File System Implementation.pptx
File System Implementation.pptxFile System Implementation.pptx
File System Implementation.pptx
 
Consensus Algorithms.pptx
Consensus Algorithms.pptxConsensus Algorithms.pptx
Consensus Algorithms.pptx
 
Security services and mechanisms
Security services and mechanismsSecurity services and mechanisms
Security services and mechanisms
 
Wireless transmission
Wireless transmissionWireless transmission
Wireless transmission
 
Guided Transmission Media
Guided  Transmission MediaGuided  Transmission Media
Guided Transmission Media
 
Input of graphical data
Input of graphical dataInput of graphical data
Input of graphical data
 
Clipping
ClippingClipping
Clipping
 
Heaptree
HeaptreeHeaptree
Heaptree
 
Deadlock
DeadlockDeadlock
Deadlock
 

Recently uploaded

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
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
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
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
 
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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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🔝
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.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
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).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
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 

Deadlock

  • 1. DEADLOCK PREVENTION & RECOVERY I am S.RAJAPRIYA I am here because I love to give a fright. You can find me at rajapriya@vvvcollege.org
  • 2. DEADLOCK 2 ✘ The Deadlock Problem ✘ System Model ✘ Deadlock Characterization ✘ Methods for Handling Deadlocks ✘ Deadlock Prevention ✘ Deadlock Avoidance ✘ Deadlock Detection ✘ Recovery from Deadlock
  • 3. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set Example System has 2 disk drives P1 and P2 each hold one disk drive and each needs another one 3
  • 4. “A Deadlock is a permanent blocking of a set of threads” 4
  • 5. SYSTEM MODEL ✘ Resources typesR1, R2, . . ., Rm CPU cycles, memory space, I/O devices ✘ Each resource type Ri has Wi instances. ✘ Each process utilizes a resource as follows: ✗ request ✗ use ✗ release 5
  • 6. Mutual exclusion : only one process at a time can use a resource. If another process request that resource, the requesting process must be delayed until the resource has been released Hold and wait : a process holding at least one resource is waiting to acquire additional resources held by other processes Deadlock Characterization No preemption : a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait : there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0. 6
  • 7. RESOURCE ALLOCATION GRAPH Deadlock can be described more precisely in terms of a directed graph called a system resource allocation graph. A set of vertices V and a set of edges E. V is partitioned into two types: • P = {P1, P2, …, Pn}, the set consisting of all the processes in the system • R = {R1, R2, …, Rm}, the set consisting of all resource types in the system • request edge – directed edge P1  Rj • assignment edge – directed edge Rj  Pi Example 7
  • 8. Resource-Allocation Graph ✘ Pictorially, we represent ✘ Process ✘ Resource Type with 4 instances ✘ Pi requests instance of Rj ✘ Pi is holding an instance of Rj 8 Pi Pi
  • 9. Example of a Resource Allocation Graph • The sets P,R,E: o P={p1,p2,p3} o R={R1,R2,R3,R4} o E={P1->R1,P2->R3,R1->P2, R2->P2,R2->P1,R3->P3} 9
  • 10. Resource Allocation Graph with Deadlock • Suppose that process P3 request an instance of resource type R3. • Since no resource is currently available, a request edge P3->R2 is added to the graph. • At this point two cycles exist in the system: ✘ P1->R1->P2->R3->P3->R2->P1 ✘ P2->R3->P3->R2->P2 • Processes P1,P2,P3 are deadlocked. 10
  • 11. Graph with a Cycle but No Deadlock • In this example we also have a cycle ✘ P1->R1->P3->R2->P1 • However, there is no cycle. • Observe that process P4 may release its resource R2.That resource can then be allocated to P3,breaking the cycle. 11
  • 12. ✘ If graph contains no cycles  no deadlock ✘ If graph contains a cycle  ✗ if only one instance per resource type, then deadlock ✗ if several instances per resource type, possibility of deadlock 12
  • 13. DEADLOCK PREVENTION ✘ By ensuring that at least one of these conditions cannot hold, We can prevent the occurrence of a deadlock 13
  • 14. Eliminate Mutual Exclusion – not required for sharable resources, must hold for non-sharable resources. For example, a printer cannot be shared by several processes. Read only files are good example of sharable resource Eliminate Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources. Deadlock Prevention ✗ Allocate all required resources to the process before the start of its execution, this way hold and wait condition is eliminated but it will lead to low device utilization. ✗ For example, if a process requires printer at a later time and we have allocated printer before the start of its execution printer will remain blocked till it has completed its execution. ✗ The process will make a new request for resources after releasing the current set of resources. This solution may lead to starvation. 14
  • 15. Eliminate No Preemption – ✗ If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. ✗ Preempted resources are added to the list of resources for which the process is waiting. Deadlock Prevention ✘ Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. 15
  • 16. Deadlock Prevention Eliminate Circular Wait – • Each resource will be assigned with a numerical number. A process can request the resources increasing/decreasing order of numbering. • For Example, if P1 process is allocated R5 resources, now next time if P1 ask for R4, R3 lesser than R5 such request will not be granted, only request for resources more than R5 will be granted. 16
  • 17. A picture is worth a thousand words 17
  • 18. Safe State!When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in safe state if there exists a safe sequence of all processes. Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j<I. ✗ If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished. ✗ When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. ✗ When Pi terminates, Pi+1 can obtain its needed resources, and so on. 18
  • 19. 19 Safe, Unsafe and Deadlock State Place your screenshot here
  • 20. Recovery from Deadlock 20 Process Termination Resource Preemption
  • 21. Process Termination Abort all deadlocked processes Abort one process at a time until the deadlock cycle is eliminated In which order should we choose to abort? 21
  • 22. Resource Preemption Selecting a victim Starvation – same process may always be picked as victim, include number of rollback in cost factor Rollback – return to some safe state, restart process for that state. 22