SlideShare uma empresa Scribd logo
1 de 11
Operating Systems
1
A Case Study
On
Deadlock
4th
CSE ‘S’
Prepared by
Yash P. Dhol
Asimhusen N.Saiyad
Jay Pandya
Submitted to
Prof. Nikul Virapariya
Operating Systems
2“Crises and deadlocks when they occur have at least this advantage that
they force us to think.”- Jawaharlal Nehru (1889 - 1964)
Definition:
“A set of processes is deadlocked if each process in the set is waiting
for an event that only another process in the set can cause”.
An example from US Kansas law:
“When two trains approach each other at a crossing, both shall come to a full
stop and neither shall start up again until the other has gone.”
For another example,
Two processes each want to record a scanned document on a CD.Process A
requests permission to use the scanner and is granted it.Process B is
programmed differently and requests the CD recorder first and is also granted
it.Now A asks for the CD recorder, but the request is denied until B releases
it.Unfortunately, instead of releasing the CD recorder B asks for the
scanner.At this point both processes are blocked and will remain so forever.
This situation is called a deadlock.
Deadlocks can occur in a variety of situations besides requesting dedicated
I/O devices.
For example If process A locks record R1 and process B locks record R2, and
then each process tries to lock the other one's record, we also have a
deadlock. Thus deadlocks can occur on hardware resources or on software
resources.
Preemptable and Nonpreemptable Resources
Resources come in two flavors: Preemptable and Nonpreemptable. A
preemptable resource is one that can be taken away from the process with no
ill effects. Memory is an example of a preemptable resource. On the other
hand, a nonpreemptable resource is one that cannot be taken away from
process (without causing ill effect). For example, CD resources are no
preemptable at an arbitrary moment. Reallocating resources can resolve
deadlocks that involve preemptable resources. Deadlocks that involve
nonpreemptable resources are difficult to deal with.
Necessary Conditions for Deadlock:
Mutual Exclusion Condition:
Explanation: At least one resource (thread) must be held in a non-shareable
mode, that is, only one process at a time claims exclusive control of the
resource.If another process requests that resource, the requesting process
must be delayed until the resource has been released.
Hold and Wait Condition:
Operating Systems
3
Explanation: There must exist a process that is holding a resource already
allocated to it while waiting for additional resource that are currently being
held by other processes.
No-Preemptive Condition:
Explanation: Resources cannot be removed from the processes are used to
completion or released voluntarily by the process holding it.
Circular Wait Condition:
Explanation: There exists a set {T1, …, Tn} of waiting threads
• T1 is waiting for a resource that is held by T2
• T2 is waiting for a resource that is held by T3
• …
• Tn is waiting for a resource that is held by T1
T1
T2
R2 R1
Operating Systems
4
That means no Deadlock occurs..
Operating Systems
5
Ways of Handling Deadlock:
• Deadlock Prevention
• Deadlock Detection
• Deadlock Recovery
• Deadlock Avoidance
Deadlock Prevention:
Remove the possibility of deadlock occurring by denying one of the four
necessary conditions:
– Mutual Exclusion (Can we share everything?)
Operating Systems
6
Removing the mutual exclusion condition means that no process
will have exclusive access to a resource.
– Hold & Wait
The hold & wait or resource holding conditions may be removed
by requiring processes to request all the resources they will need
before starting up.
– No preemption
The No preemption condition may also be difficult or impossible
to avoid as a process has to be able to have a resource for a
certain amount of time, or the processing outcome may be
inconsistent.
However, inability to enforce preemption may interfere with
a priority algorithm.
– Circular Wait
The final condition is the circular wait condition. Approaches that
avoid circular waits include disabling interrupts during critical
sections.
Deadlock Detection:
Deadlock Detection with One Resource of Each
Type
Operating Systems
7
1. Process A holds R and wants S.
2. Process B holds nothing but wants T.
3. Process C holds nothing but wants S.
4. Process D holds U and wants V.
5. Process E holds T and wants V.
6. Process F holds W and wants S.
7. Process G holds V wants U.
Deadlock Recovery:
• Recovery through preemption
– take a resource from some other process
• Recovery through rollback
– checkpoint a process periodically
– use this saved state
– restart the process if it is found deadlocked
• Recovery through killing processes
– crudest but simplest way to break a deadlock
– kill one of the processes in the deadlock cycle
– the other processes get its resources
Operating Systems
8
– choose process that can be rerun from the beginning
Deadlock Avoidance:
This approach to the deadlock problem anticipates deadlock before it actually
occurs.
This method differs from deadlock prevention, which guarantees that deadlock
cannot occur by denying one of the necessary conditions of deadlock.
If the necessary conditions for a deadlock are in place, it is still possible to
avoid deadlock by being careful when resources are allocated.
Perhaps the most famous deadlock avoidance algorithm, due to Dijkstra
[1965], is the Banker’s algorithm.
So named because the process is analogous to that used by a banker in
deciding if a loan can be safely made.
Safe State The key to a state being safe is that there is at least one way for all
users to finish. In other analogy, the state of figure 2 is safe because with 2
units left, the banker can delay any request except C's,
thus letting C finish and release all four resources. With four units in hand, the
banker can let either D or B have the necessary units and so on.
Customers Used Max
A 1 6
B 1 5
C 2 4
D 4 7
Available Units= 2
Operating Systems
9
Unsafe State Consider what would happen if a request from B for one more
unit were grantedin above We would have following situation
Available Units = 1
Customers Used Max
A 1 6
B 2 5
C 2 4
D 4 7
This is an unsafe state. If all the customers namely A, B, C, and D asked for
their maximum loans, then banker could not satisfy any of them and we would
have a deadlock.
• Three resource allocation states
– safe
– safe
– unsafe
Operating Systems
10
The Banker’s Algoritham for Multiple Resources:
E = (6, 3, 4, 2) P = (5, 3, 2, 2) A = (1, 0, 2, 0)
Notice that A = E - P
Going thru this algorithm with the foregoing data, we see that process D's
requirements are smaller than A, so we virtually terminate D and add its
resources back into the available pool:
E = (6, 3, 4, 2)
P = (5, 3, 2, 2) - (1, 1, 0, 1) = (4, 2, 2, 1)
A = (1, 0, 2, 0) + (1, 1, 0, 1) = (2, 1, 2, 1)
Now, A's requirements are less than A, so do the same thing with A:
P = (4, 2, 2, 1) - (3, 0, 1, 1) = (1, 2, 1, 0)
A = (2, 1, 2, 1) + (3, 0, 1, 1) = (5, 1, 3, 2)
At this point, we see that there are no remaining processes that can't be satisfied
from available resources, so the illustrated state is safe.
Operating Systems
11
Thank you

Mais conteúdo relacionado

Mais procurados

12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
myrajendra
 
Process management in os
Process management in osProcess management in os
Process management in os
Sumant Diwakar
 

Mais procurados (20)

Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Load balancing in Distributed Systems
Load balancing in Distributed SystemsLoad balancing in Distributed Systems
Load balancing in Distributed Systems
 
File system security
File system securityFile system security
File system security
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
Distributed DBMS - Unit 8 - Distributed Transaction Management & Concurrency ...
 
Cache memory presentation
Cache memory presentationCache memory presentation
Cache memory presentation
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
Cs8493 unit 3
Cs8493 unit 3Cs8493 unit 3
Cs8493 unit 3
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphores
 
Cs8493 unit 4
Cs8493 unit 4Cs8493 unit 4
Cs8493 unit 4
 
Process Management-Process Migration
Process Management-Process MigrationProcess Management-Process Migration
Process Management-Process Migration
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Paging and Segmentation in Operating System
Paging and Segmentation in Operating SystemPaging and Segmentation in Operating System
Paging and Segmentation in Operating System
 
Buffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya JyothiBuffer cache unix ppt Mrs.Sowmya Jyothi
Buffer cache unix ppt Mrs.Sowmya Jyothi
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 

Semelhante a Os case study word

Semelhante a Os case study word (20)

Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
Deadlock Slides
Deadlock SlidesDeadlock Slides
Deadlock Slides
 
4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Module3
Module3Module3
Module3
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlock
DeadlockDeadlock
Deadlock
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Deadlocks final
Deadlocks finalDeadlocks final
Deadlocks final
 
3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptx3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptx
 
OS 7.pptx
OS 7.pptxOS 7.pptx
OS 7.pptx
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
Chapter06
Chapter06Chapter06
Chapter06
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 

Último

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Último (20)

Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Wadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptxWadi Rum luxhotel lodge Analysis case study.pptx
Wadi Rum luxhotel lodge Analysis case study.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 

Os case study word

  • 1. Operating Systems 1 A Case Study On Deadlock 4th CSE ‘S’ Prepared by Yash P. Dhol Asimhusen N.Saiyad Jay Pandya Submitted to Prof. Nikul Virapariya
  • 2. Operating Systems 2“Crises and deadlocks when they occur have at least this advantage that they force us to think.”- Jawaharlal Nehru (1889 - 1964) Definition: “A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause”. An example from US Kansas law: “When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone.” For another example, Two processes each want to record a scanned document on a CD.Process A requests permission to use the scanner and is granted it.Process B is programmed differently and requests the CD recorder first and is also granted it.Now A asks for the CD recorder, but the request is denied until B releases it.Unfortunately, instead of releasing the CD recorder B asks for the scanner.At this point both processes are blocked and will remain so forever. This situation is called a deadlock. Deadlocks can occur in a variety of situations besides requesting dedicated I/O devices. For example If process A locks record R1 and process B locks record R2, and then each process tries to lock the other one's record, we also have a deadlock. Thus deadlocks can occur on hardware resources or on software resources. Preemptable and Nonpreemptable Resources Resources come in two flavors: Preemptable and Nonpreemptable. A preemptable resource is one that can be taken away from the process with no ill effects. Memory is an example of a preemptable resource. On the other hand, a nonpreemptable resource is one that cannot be taken away from process (without causing ill effect). For example, CD resources are no preemptable at an arbitrary moment. Reallocating resources can resolve deadlocks that involve preemptable resources. Deadlocks that involve nonpreemptable resources are difficult to deal with. Necessary Conditions for Deadlock: Mutual Exclusion Condition: Explanation: At least one resource (thread) must be held in a non-shareable mode, that is, only one process at a time claims exclusive control of the resource.If another process requests that resource, the requesting process must be delayed until the resource has been released. Hold and Wait Condition:
  • 3. Operating Systems 3 Explanation: There must exist a process that is holding a resource already allocated to it while waiting for additional resource that are currently being held by other processes. No-Preemptive Condition: Explanation: Resources cannot be removed from the processes are used to completion or released voluntarily by the process holding it. Circular Wait Condition: Explanation: There exists a set {T1, …, Tn} of waiting threads • T1 is waiting for a resource that is held by T2 • T2 is waiting for a resource that is held by T3 • … • Tn is waiting for a resource that is held by T1 T1 T2 R2 R1
  • 4. Operating Systems 4 That means no Deadlock occurs..
  • 5. Operating Systems 5 Ways of Handling Deadlock: • Deadlock Prevention • Deadlock Detection • Deadlock Recovery • Deadlock Avoidance Deadlock Prevention: Remove the possibility of deadlock occurring by denying one of the four necessary conditions: – Mutual Exclusion (Can we share everything?)
  • 6. Operating Systems 6 Removing the mutual exclusion condition means that no process will have exclusive access to a resource. – Hold & Wait The hold & wait or resource holding conditions may be removed by requiring processes to request all the resources they will need before starting up. – No preemption The No preemption condition may also be difficult or impossible to avoid as a process has to be able to have a resource for a certain amount of time, or the processing outcome may be inconsistent. However, inability to enforce preemption may interfere with a priority algorithm. – Circular Wait The final condition is the circular wait condition. Approaches that avoid circular waits include disabling interrupts during critical sections. Deadlock Detection: Deadlock Detection with One Resource of Each Type
  • 7. Operating Systems 7 1. Process A holds R and wants S. 2. Process B holds nothing but wants T. 3. Process C holds nothing but wants S. 4. Process D holds U and wants V. 5. Process E holds T and wants V. 6. Process F holds W and wants S. 7. Process G holds V wants U. Deadlock Recovery: • Recovery through preemption – take a resource from some other process • Recovery through rollback – checkpoint a process periodically – use this saved state – restart the process if it is found deadlocked • Recovery through killing processes – crudest but simplest way to break a deadlock – kill one of the processes in the deadlock cycle – the other processes get its resources
  • 8. Operating Systems 8 – choose process that can be rerun from the beginning Deadlock Avoidance: This approach to the deadlock problem anticipates deadlock before it actually occurs. This method differs from deadlock prevention, which guarantees that deadlock cannot occur by denying one of the necessary conditions of deadlock. If the necessary conditions for a deadlock are in place, it is still possible to avoid deadlock by being careful when resources are allocated. Perhaps the most famous deadlock avoidance algorithm, due to Dijkstra [1965], is the Banker’s algorithm. So named because the process is analogous to that used by a banker in deciding if a loan can be safely made. Safe State The key to a state being safe is that there is at least one way for all users to finish. In other analogy, the state of figure 2 is safe because with 2 units left, the banker can delay any request except C's, thus letting C finish and release all four resources. With four units in hand, the banker can let either D or B have the necessary units and so on. Customers Used Max A 1 6 B 1 5 C 2 4 D 4 7 Available Units= 2
  • 9. Operating Systems 9 Unsafe State Consider what would happen if a request from B for one more unit were grantedin above We would have following situation Available Units = 1 Customers Used Max A 1 6 B 2 5 C 2 4 D 4 7 This is an unsafe state. If all the customers namely A, B, C, and D asked for their maximum loans, then banker could not satisfy any of them and we would have a deadlock. • Three resource allocation states – safe – safe – unsafe
  • 10. Operating Systems 10 The Banker’s Algoritham for Multiple Resources: E = (6, 3, 4, 2) P = (5, 3, 2, 2) A = (1, 0, 2, 0) Notice that A = E - P Going thru this algorithm with the foregoing data, we see that process D's requirements are smaller than A, so we virtually terminate D and add its resources back into the available pool: E = (6, 3, 4, 2) P = (5, 3, 2, 2) - (1, 1, 0, 1) = (4, 2, 2, 1) A = (1, 0, 2, 0) + (1, 1, 0, 1) = (2, 1, 2, 1) Now, A's requirements are less than A, so do the same thing with A: P = (4, 2, 2, 1) - (3, 0, 1, 1) = (1, 2, 1, 0) A = (2, 1, 2, 1) + (3, 0, 1, 1) = (5, 1, 3, 2) At this point, we see that there are no remaining processes that can't be satisfied from available resources, so the illustrated state is safe.