SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Último (20)

Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
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
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
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
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

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