SlideShare a Scribd company logo
1 of 15
What is deadlock
• Deadlock is a situation where a set of processes are blocked
because each process is holding a resource and waiting for
another resource acquired by some other process.
P
1
P
2
R1 R2
Necessary Condition for Deadlocks
 Mutual Exclusion: If two process cannot share same resource
at same time.
 Hold and Wait: A process wait for some resources while
holding any another resource at the same time.
 No pre-emption: The process which once scheduled will be
executed till completion.
 Circular wait: All the processes must be waiting for the
resource in a cyclic manner.
R1 R2 R3
P
1
P
2
P
3
Method of Handling Deadlock
There are four approaches to dealing with deadlocks.
 Deadlock ignorance
 Deadlock avoidance
 Deadlock prevention
 Deadlock detection & Recovery
Deadlock Avoidance
 The deadlock avoidance algorithm is designed to minimize
the chances of deadlock occurring.
 The resources currently available.
 The recources currently allocated to each process.
 Deadlock can be avoided by maintaining the system always in
safe state.
 Safe sequence : The sequence in which the pending process
can successfully executed.
Banker’s Algorithm
Process Allocation Max Available Remaining ->Max-allocate
R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3
P1 0 1 0 7 5 3 3 3 2 7 4 3 Need<=work
+2 0 0
P2 2 0 0 3 2 2 5 3 2 1 2 2
+2 1 1
P3 3 0 2 9 0 2 7 4 3 6 0 0
+0 1 0
P4 2 1 1 2 2 2 7 5 3 0 1 1
+3 0 2 Safe Sequence
7 2 3 10 5 5 P2 -> P4 -> P1 ->P3
Given-
R1-10 R2-5 R3-5
Deadlock Prevention
Elimination of
• Mutual Exclusion
• Hold and Wait Condition
• No Preemption Condition
• Circular Condition
Mutual Exclusion-
We can deny this situation by simple protocol i.e by
“By Converting all non shareable resources to shareable resources”
Hold and wait-
We can deny this situation with the following protocols-
1. A process can request the resources only when the process has
none.
2. Each process to request and be allocated all its resources before it
begins execution.
No Preemption-
To ensure this condition does not hold we use the following protocols-
1. We preempt the desired resources from the waiting process and
allocate them to the requesting process.
Circular Wait-
We ensure that the circular wait must not happen so we apply a simple
solution-
1. Numbering all the resouce type and each process request
resources in an increasing order of ennumeration.
Deadlock Detection
 As we can understand from name here we check safety and detect if any deadlock
has occurred.
Here DeadLock can be occurred and can be detected using different approaches.
1. Active Approach
2. Lazy Approach
 Algorithms used for deadlock detection and recovery are-
a) For Single Instance of each resource type
b) For Multi instance of resource type
Single Instance of Each Resource Type
P1 P2 P3
P4
P5
R1 R3 R4
R2 R5
Resource Allocation Graph
P4
P2
P1 P3
P5
Corresponding wait for graph
Cycle
Occurs
Process Allocation Request Available
A B C A B C A B C
P1 0 1 0 0 0 0 0 0 0
P2 2 0 0 2 0 2 0 1 0
P3 3 0 3 0 0 0 3 1 3
P4 2 1 1 1 0 0 5 2 4
5 2 6
P5 0 0 2 0 0 2 7 2 6
Given-
A-7 B-2 C-6
+7 2 6
Request < =Available
Available= Available +
Allocated of used
process
SAFE SEQUENCE-
<P1, P3, P4 ,P5 ,P2>
•No Deadlock will
Occur if we follow
this sequence for
allocating resources .
For Multi Instance of Resource Type
Recovery From Deadlock
1. Process Termination-
• Abort all deadlock processes
• Abort one process at a time until the deadlock cycle is eliminated.
2. Resource Preemption-
• Selecting a victim
• Rollback
• Starvation
What is deadlock and how to prevent, detect, and recover from it
What is deadlock and how to prevent, detect, and recover from it

More Related Content

Similar to What is deadlock and how to prevent, detect, and recover from it

OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptxKokilaK25
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserMatthew Chang
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptxDenisPriscus
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptxsheraz7288
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)WajeehaBaig
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptxshrijanasharma3
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptamadayshwan
 
Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection AlgorithmMohammad Qureshi
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxBhaskar271887
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoorWani Zahoor
 
Os case study word
Os case study wordOs case study word
Os case study wordDhol Yash
 

Similar to What is deadlock and how to prevent, detect, and recover from it (20)

OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
 
Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
Deadlocks
 Deadlocks Deadlocks
Deadlocks
 
Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Os case study word
Os case study wordOs case study word
Os case study word
 
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
 
6. Deadlock.ppt
6. Deadlock.ppt6. Deadlock.ppt
6. Deadlock.ppt
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
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
 
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
 
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
 
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
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
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
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
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
 
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
 
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
 
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
 
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...
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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
 
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
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
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
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 

What is deadlock and how to prevent, detect, and recover from it

  • 1.
  • 2. What is deadlock • Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. P 1 P 2 R1 R2
  • 3. Necessary Condition for Deadlocks  Mutual Exclusion: If two process cannot share same resource at same time.  Hold and Wait: A process wait for some resources while holding any another resource at the same time.  No pre-emption: The process which once scheduled will be executed till completion.  Circular wait: All the processes must be waiting for the resource in a cyclic manner. R1 R2 R3 P 1 P 2 P 3
  • 4. Method of Handling Deadlock There are four approaches to dealing with deadlocks.  Deadlock ignorance  Deadlock avoidance  Deadlock prevention  Deadlock detection & Recovery
  • 5. Deadlock Avoidance  The deadlock avoidance algorithm is designed to minimize the chances of deadlock occurring.  The resources currently available.  The recources currently allocated to each process.  Deadlock can be avoided by maintaining the system always in safe state.  Safe sequence : The sequence in which the pending process can successfully executed.
  • 6. Banker’s Algorithm Process Allocation Max Available Remaining ->Max-allocate R1 R2 R3 R1 R2 R3 R1 R2 R3 R1 R2 R3 P1 0 1 0 7 5 3 3 3 2 7 4 3 Need<=work +2 0 0 P2 2 0 0 3 2 2 5 3 2 1 2 2 +2 1 1 P3 3 0 2 9 0 2 7 4 3 6 0 0 +0 1 0 P4 2 1 1 2 2 2 7 5 3 0 1 1 +3 0 2 Safe Sequence 7 2 3 10 5 5 P2 -> P4 -> P1 ->P3 Given- R1-10 R2-5 R3-5
  • 7. Deadlock Prevention Elimination of • Mutual Exclusion • Hold and Wait Condition • No Preemption Condition • Circular Condition
  • 8. Mutual Exclusion- We can deny this situation by simple protocol i.e by “By Converting all non shareable resources to shareable resources” Hold and wait- We can deny this situation with the following protocols- 1. A process can request the resources only when the process has none. 2. Each process to request and be allocated all its resources before it begins execution.
  • 9. No Preemption- To ensure this condition does not hold we use the following protocols- 1. We preempt the desired resources from the waiting process and allocate them to the requesting process. Circular Wait- We ensure that the circular wait must not happen so we apply a simple solution- 1. Numbering all the resouce type and each process request resources in an increasing order of ennumeration.
  • 10. Deadlock Detection  As we can understand from name here we check safety and detect if any deadlock has occurred. Here DeadLock can be occurred and can be detected using different approaches. 1. Active Approach 2. Lazy Approach  Algorithms used for deadlock detection and recovery are- a) For Single Instance of each resource type b) For Multi instance of resource type
  • 11. Single Instance of Each Resource Type P1 P2 P3 P4 P5 R1 R3 R4 R2 R5 Resource Allocation Graph P4 P2 P1 P3 P5 Corresponding wait for graph Cycle Occurs
  • 12. Process Allocation Request Available A B C A B C A B C P1 0 1 0 0 0 0 0 0 0 P2 2 0 0 2 0 2 0 1 0 P3 3 0 3 0 0 0 3 1 3 P4 2 1 1 1 0 0 5 2 4 5 2 6 P5 0 0 2 0 0 2 7 2 6 Given- A-7 B-2 C-6 +7 2 6 Request < =Available Available= Available + Allocated of used process SAFE SEQUENCE- <P1, P3, P4 ,P5 ,P2> •No Deadlock will Occur if we follow this sequence for allocating resources . For Multi Instance of Resource Type
  • 13. Recovery From Deadlock 1. Process Termination- • Abort all deadlock processes • Abort one process at a time until the deadlock cycle is eliminated. 2. Resource Preemption- • Selecting a victim • Rollback • Starvation