SlideShare a Scribd company logo
1 of 32
Operating Systems
LECTURE# 6 DEADLOCKS
1
What is dead lock
 In multiprogramming environment , several processes
compete for resources. A situation may arise where a
process is waiting for resources that is held by other
waiting processes. This situation is called a dead lock.
2
 Deadlock is defined as a situation where set of
processes are blocked because
each process holding a resource and waiting to
acquire a resource held by another process,
 A deadlock happens in operating system when two or
more processes need some resource to complete
their execution that is held by the other process.
3
Deadlock…
 Consider an example when two trains/ vehicle are coming toward
each other on same track and there is only one track, none of the
trains can move once they are in front of each other.
 Similar situation occurs in operating systems.
4
Note:
 A process in operating systems uses different resources , the resources are
used in the following way.
1) Requests a resource
2) Use the resource
2) Releases the resource
5
Dead lock Example 6
Dead lock….
 In the above diagram, the process 1 has resource 1 and needs to
acquire resource 2.
 Similarly process 2 has resource 2 and needs to acquire resource 1.
 Process 1 and process 2 are in deadlock as each of them needs the
other’s resource to complete their execution but neither of them is
willing to release their resources.
7
Deadlock Example
 One process has access to printer but is waiting for tap drive ,
while another process has access to tape drive but is waiting for
printer.
8
Resources
 A resources is an object that is used by a process. It can be a piece of hardware
such as
 Tape drive
 Printer
 Scanner
 Buffers
 Memory etc.
9
Types of Resources
1) Pre-emptible Resources :
A Pre-emptible Resource is one that can be allocated to a given process for a
period of time. Then it can be allocated to another process. Then its can reallocated
to the first process without any negative effects.
Example: memory, buffers etc.
2) Non Pre-emptible Resources :
A Non Pre-emptible Resource cannot be taken from one process and given to
another without side effects.
One example is printer. A printer cannot be taken away from one process and given
to another process in the middle of a print job.
Note: Deadlocks usually involve Non Pre-emptible Resources.
10
6.3 Deadlock Characterization
 Deadlock can arise if following four conditions take place
simultaneously in a system. (Necessary Conditions)
1) Mutual Exclusion
2) Hold and Wait
3) No Preemption
4) Circular Wait
11
Deadlock Characterization
1) Mutual Exclusion: Only one process at a time can use a
resource. If another process request that resources the
requesting process will delayed until the resource has
been released .
In the diagram below, there is a single instance of Resource
1 and it is held by Process 1 only.
12
 2) Hold and Wait: A process must be holding at least one
resource and waiting to acquire additional resources that are
concurrently being held by other processes.
 In the diagram given above, Process 2 holds Resource 2 and
Resource 3 and is requesting the Resource 1 which is held by
Process 1.
13
3) No preemption: A resource can be released only voluntarily
by the process holding it, after that process has completed its
task. OR
A resource cannot be preempted from a process by force. A
process can only release a resource voluntarily.
In the diagram, Process 2 cannot preempt Resource 1 from Process
1. It will only be released when Process 1 release it voluntarily
after its execution is complete.
14
4) Circular Wait:
There exists a set {P0, P1, …, Pn} 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 Pn is waiting for a resource that is held by P0.
15
OR
 A process is waiting for the resource held by the
second process, which is waiting for the resource
held by the third process and so on, till the last
process is waiting for a resource held by the first
process. This forms a circular chain..
16
 For example: Process 1 is allocated Resource2 and it is
requesting Resource 1. Similarly, Process 2 is allocated
Resource 1 and it is requesting Resource 2. This forms a
circular wait loop
17
Deadlock Detection
 A deadlock can be detected by a resource scheduler as it
keeps track of all the resources that are allocated to
different processes. After a deadlock is detected, it can be
resolved using the following methods
 All the processes that are involved in the deadlock are
terminated. This is not a good approach as all the progress
made by the processes is destroyed.
 Resources can be preempted from some processes and given
to others till the deadlock is resolved.
18
Method for Handling Deadlocks
1. Deadlock Prevention
2. Deadlock Avoidance
3. Deadlock Detection and Recovery
19
Deadlock Prevention
 We can prevent deadlocks by ensuring that at least one of the four
necessary conditions for deadlock cannot occur. If at least one condition is
not satisfied, a deadlock will not occur.
20
Deadlock Prevention…..
 1) Mutual Exclusion
 Mutual exclusion condition must hold for non-sharable resources.
 For example, only one process can have access to a printer at a time, otherwise
the output is disturbed.
 Some resources can be made sharable like a read-only file.
 Several processes can be granted read- only access to a file without interfering
with each other.
 However, deadlock cannot be prevented by only denying the mutual exclusion
condition because some resources are intrinsically (by birth) non-sharable.
21
Deadlock Prevention…..
 Elimination of Mutual Exclusion
 If it is shareable resource, then we can break the mutual exclusion (such as:
Read-only file)
 If it is not a shareable resource, then mutual exclusion must hold (such as:
Printer) because non shareable means that their states cannot be saved and
restored without ill effects.
22
Deadlock Prevention…..
2) Elimination of Hold and wait: two methods
 A) Require process to request and be allocated all its resources before it begins
execution.
 B) Allow process to request resources only when the process has none.
 Example:
 We consider a process that copies data from DVD drive to a picture file on disk
and then prints the picture to a printer
 Method 1: Request DVD drive, Disk, and Printer before it execute. It will hold
the Printer for entire execution, even though it needs the printer only at the end.
 Method2: Request only for DVD drive and Disk initially. It finishes the copy step
and releases both resources. The process must then again ask for disk and printer
To finish the job.
23
Deadlock Prevention…..
 3) Elimination of No preemption:
 a) Release any resource already being held if the process can't get an
additional resource.
 b) Allow preemption - if a needed resource is held by another process,
which is also waiting on some resource, steal it. Otherwise wait.
 c) Process will be restarted only when it can regain its old Resources, as
well as the new ones that it is requesting.
24
Deadlock Prevention…..
4) Elimination of Circular wait
 Each resource will be assigned with a numerical number. A process
can request the resources only in increasing 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.
25
Deadlock Avoidance
 Deadlock avoidance can be done with help of Banker’s Algorithm.
 Banker’s Algorithm:
 Bankers' Algorithm is resource allocation and deadlock avoidance
algorithm which test all the request made by processes for resources,
it checks for the safe state, if after granting request system remains
in the safe state it allows the request and if there is no safe state it
doesn’t allow the request made by the process.
26
Safe State and Unsafe State
 A state is said to be a safe state if the system may allocate
the required resources to each process up to the maximum
required in a particular sequence without facing deadlock.
 In safe state , deadlock cannot occur.
 If a deadlock is possible the system is said to be in an
unsafe state.
 The idea of avoiding a deadlock is to simply not allow the
system to enter an unsafe state that may cause a deadlock
27
Inputs to Banker’s Algorithm:
1) Max need of resources by each process.
2) Currently allocated resources by each
process.
3) Max free available resources in the
system.
28
Banker’s Algorithm step….
 Need is less than or equal to work then
 Work= work + allocation
29
6.4.3 Deadlock Detection and Recovery 30
Deadlock Detection and Recovery… 31
32

More Related Content

What's hot

What's hot (20)

Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Deadlock detection
Deadlock detectionDeadlock detection
Deadlock detection
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddikDeadlock in distribute system by saeed siddik
Deadlock in distribute system by saeed siddik
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbianDeadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbian
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 

Similar to Operating system Deadlock

4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptxDishaDwivedi2
 
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.pptxsvulasal
 
Os case study word
Os case study wordOs case study word
Os case study wordDhol Yash
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].pptamadayshwan
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemEktaVaswani2
 
Deadlockproj.pptx
Deadlockproj.pptxDeadlockproj.pptx
Deadlockproj.pptxsonu642319
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)WajeehaBaig
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoorWani Zahoor
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232marangburu42
 

Similar to Operating system Deadlock (20)

4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
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 case study word
Os case study wordOs case study word
Os case study word
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
Unit iv: Deadlocks
Unit iv: DeadlocksUnit iv: Deadlocks
Unit iv: Deadlocks
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
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
 
Deadlockproj.pptx
Deadlockproj.pptxDeadlockproj.pptx
Deadlockproj.pptx
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
ikh311-05
ikh311-05ikh311-05
ikh311-05
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Module3
Module3Module3
Module3
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 

Recently uploaded

Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...NETWAYS
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...NETWAYS
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 

Recently uploaded (20)

Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
OSCamp Kubernetes 2024 | A Tester's Guide to CI_CD as an Automated Quality Co...
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
OSCamp Kubernetes 2024 | Zero-Touch OS-Infrastruktur für Container und Kubern...
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Vaishnavi 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Vaishnavi 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 

Operating system Deadlock

  • 2. What is dead lock  In multiprogramming environment , several processes compete for resources. A situation may arise where a process is waiting for resources that is held by other waiting processes. This situation is called a dead lock. 2
  • 3.  Deadlock is defined as a situation where set of processes are blocked because each process holding a resource and waiting to acquire a resource held by another process,  A deadlock happens in operating system when two or more processes need some resource to complete their execution that is held by the other process. 3
  • 4. Deadlock…  Consider an example when two trains/ vehicle are coming toward each other on same track and there is only one track, none of the trains can move once they are in front of each other.  Similar situation occurs in operating systems. 4
  • 5. Note:  A process in operating systems uses different resources , the resources are used in the following way. 1) Requests a resource 2) Use the resource 2) Releases the resource 5
  • 7. Dead lock….  In the above diagram, the process 1 has resource 1 and needs to acquire resource 2.  Similarly process 2 has resource 2 and needs to acquire resource 1.  Process 1 and process 2 are in deadlock as each of them needs the other’s resource to complete their execution but neither of them is willing to release their resources. 7
  • 8. Deadlock Example  One process has access to printer but is waiting for tap drive , while another process has access to tape drive but is waiting for printer. 8
  • 9. Resources  A resources is an object that is used by a process. It can be a piece of hardware such as  Tape drive  Printer  Scanner  Buffers  Memory etc. 9
  • 10. Types of Resources 1) Pre-emptible Resources : A Pre-emptible Resource is one that can be allocated to a given process for a period of time. Then it can be allocated to another process. Then its can reallocated to the first process without any negative effects. Example: memory, buffers etc. 2) Non Pre-emptible Resources : A Non Pre-emptible Resource cannot be taken from one process and given to another without side effects. One example is printer. A printer cannot be taken away from one process and given to another process in the middle of a print job. Note: Deadlocks usually involve Non Pre-emptible Resources. 10
  • 11. 6.3 Deadlock Characterization  Deadlock can arise if following four conditions take place simultaneously in a system. (Necessary Conditions) 1) Mutual Exclusion 2) Hold and Wait 3) No Preemption 4) Circular Wait 11
  • 12. Deadlock Characterization 1) Mutual Exclusion: Only one process at a time can use a resource. If another process request that resources the requesting process will delayed until the resource has been released . In the diagram below, there is a single instance of Resource 1 and it is held by Process 1 only. 12
  • 13.  2) Hold and Wait: A process must be holding at least one resource and waiting to acquire additional resources that are concurrently being held by other processes.  In the diagram given above, Process 2 holds Resource 2 and Resource 3 and is requesting the Resource 1 which is held by Process 1. 13
  • 14. 3) No preemption: A resource can be released only voluntarily by the process holding it, after that process has completed its task. OR A resource cannot be preempted from a process by force. A process can only release a resource voluntarily. In the diagram, Process 2 cannot preempt Resource 1 from Process 1. It will only be released when Process 1 release it voluntarily after its execution is complete. 14
  • 15. 4) Circular Wait: There exists a set {P0, P1, …, Pn} 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 Pn is waiting for a resource that is held by P0. 15
  • 16. OR  A process is waiting for the resource held by the second process, which is waiting for the resource held by the third process and so on, till the last process is waiting for a resource held by the first process. This forms a circular chain.. 16
  • 17.  For example: Process 1 is allocated Resource2 and it is requesting Resource 1. Similarly, Process 2 is allocated Resource 1 and it is requesting Resource 2. This forms a circular wait loop 17
  • 18. Deadlock Detection  A deadlock can be detected by a resource scheduler as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be resolved using the following methods  All the processes that are involved in the deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed.  Resources can be preempted from some processes and given to others till the deadlock is resolved. 18
  • 19. Method for Handling Deadlocks 1. Deadlock Prevention 2. Deadlock Avoidance 3. Deadlock Detection and Recovery 19
  • 20. Deadlock Prevention  We can prevent deadlocks by ensuring that at least one of the four necessary conditions for deadlock cannot occur. If at least one condition is not satisfied, a deadlock will not occur. 20
  • 21. Deadlock Prevention…..  1) Mutual Exclusion  Mutual exclusion condition must hold for non-sharable resources.  For example, only one process can have access to a printer at a time, otherwise the output is disturbed.  Some resources can be made sharable like a read-only file.  Several processes can be granted read- only access to a file without interfering with each other.  However, deadlock cannot be prevented by only denying the mutual exclusion condition because some resources are intrinsically (by birth) non-sharable. 21
  • 22. Deadlock Prevention…..  Elimination of Mutual Exclusion  If it is shareable resource, then we can break the mutual exclusion (such as: Read-only file)  If it is not a shareable resource, then mutual exclusion must hold (such as: Printer) because non shareable means that their states cannot be saved and restored without ill effects. 22
  • 23. Deadlock Prevention….. 2) Elimination of Hold and wait: two methods  A) Require process to request and be allocated all its resources before it begins execution.  B) Allow process to request resources only when the process has none.  Example:  We consider a process that copies data from DVD drive to a picture file on disk and then prints the picture to a printer  Method 1: Request DVD drive, Disk, and Printer before it execute. It will hold the Printer for entire execution, even though it needs the printer only at the end.  Method2: Request only for DVD drive and Disk initially. It finishes the copy step and releases both resources. The process must then again ask for disk and printer To finish the job. 23
  • 24. Deadlock Prevention…..  3) Elimination of No preemption:  a) Release any resource already being held if the process can't get an additional resource.  b) Allow preemption - if a needed resource is held by another process, which is also waiting on some resource, steal it. Otherwise wait.  c) Process will be restarted only when it can regain its old Resources, as well as the new ones that it is requesting. 24
  • 25. Deadlock Prevention….. 4) Elimination of Circular wait  Each resource will be assigned with a numerical number. A process can request the resources only in increasing 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. 25
  • 26. Deadlock Avoidance  Deadlock avoidance can be done with help of Banker’s Algorithm.  Banker’s Algorithm:  Bankers' Algorithm is resource allocation and deadlock avoidance algorithm which test all the request made by processes for resources, it checks for the safe state, if after granting request system remains in the safe state it allows the request and if there is no safe state it doesn’t allow the request made by the process. 26
  • 27. Safe State and Unsafe State  A state is said to be a safe state if the system may allocate the required resources to each process up to the maximum required in a particular sequence without facing deadlock.  In safe state , deadlock cannot occur.  If a deadlock is possible the system is said to be in an unsafe state.  The idea of avoiding a deadlock is to simply not allow the system to enter an unsafe state that may cause a deadlock 27
  • 28. Inputs to Banker’s Algorithm: 1) Max need of resources by each process. 2) Currently allocated resources by each process. 3) Max free available resources in the system. 28
  • 29. Banker’s Algorithm step….  Need is less than or equal to work then  Work= work + allocation 29
  • 30. 6.4.3 Deadlock Detection and Recovery 30
  • 31. Deadlock Detection and Recovery… 31
  • 32. 32

Editor's Notes

  1. 1