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

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
Sonali Chauhan
 
12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
myrajendra
 

Mais procurados (20)

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Operating System-Process Scheduling
Operating System-Process SchedulingOperating System-Process Scheduling
Operating System-Process Scheduling
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Cs8493 unit 3
Cs8493 unit 3Cs8493 unit 3
Cs8493 unit 3
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Cyber security training at ist apr-18
Cyber security training at ist apr-18Cyber security training at ist apr-18
Cyber security training at ist apr-18
 
File system implementation
File system implementationFile system implementation
File system implementation
 
Synchronization problems
Synchronization problemsSynchronization problems
Synchronization problems
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)Ch2: Computer System Structure (OS)
Ch2: Computer System Structure (OS)
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 

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
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
 
operating system
operating systemoperating system
operating system
 

Último

DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DrGurudutt
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
Kamal Acharya
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
Kamal Acharya
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
Kamal Acharya
 

Último (20)

Top 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering ScientistTop 13 Famous Civil Engineering Scientist
Top 13 Famous Civil Engineering Scientist
 
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdfDR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
DR PROF ING GURUDUTT SAHNI WIKIPEDIA.pdf
 
Online blood donation management system project.pdf
Online blood donation management system project.pdfOnline blood donation management system project.pdf
Online blood donation management system project.pdf
 
Furniture showroom management system project.pdf
Furniture showroom management system project.pdfFurniture showroom management system project.pdf
Furniture showroom management system project.pdf
 
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and ClusteringKIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
KIT-601 Lecture Notes-UNIT-4.pdf Frequent Itemsets and Clustering
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Online book store management system project.pdf
Online book store management system project.pdfOnline book store management system project.pdf
Online book store management system project.pdf
 
İTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering WorkshopİTÜ CAD and Reverse Engineering Workshop
İTÜ CAD and Reverse Engineering Workshop
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
An improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technologyAn improvement in the safety of big data using blockchain technology
An improvement in the safety of big data using blockchain technology
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 

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.