SlideShare a Scribd company logo
Chapter-5
Deadlock
BY: MADHURI VAGHASIA
Deadlock
EXAMPLES:
1. "It takes money to make money".
2. You can't get a job without experience; you can't get experience without a job.
BACKGROUND:
◦ The cause of deadlocks: Each process needing what another process has. This results from
sharing resources such as memory, devices, links.
◦ Under normal operation, a resource allocations proceed like this::
1. Request a resource (suspend until available if necessary ).
2. Use the resource.
3. Release the resource
What is Deadlock?
for 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.
Deadlock
Bridge Crossing Example
◦ Traffic only in one direction.
◦ Each section of a bridge can be viewed as a resource.
◦ If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback).
◦ Several cars may have to be backed up if a deadlock occurs.
◦ Starvation is possible.
Deadlock
◦ Space is available for allocation of 200Kbytes, and the following sequence of events occur
◦ Deadlock occurs if both processes progress to their second request
P1
. . .
Request 80 Kbytes;
…
Request 60 Kbytes;
P2
. . .
Request 70 Kbytes;
…
Request 80 Kbytes;
Deadlock Characterization
Deadlock can arise if four conditions hold simultaneously.
1. Mutual exclusion: only one process at a time can use a resource
2. Hold and wait: a process holding at least one resource is waiting to acquire additional
resources held by other processes
3. No preemption: a resource can be released only voluntarily by the process holding it, after
that process has completed its task
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.
Resource-Allocation Graph
◦A set of vertices V and a set of edges E.
◦ V is partitioned into two types:
◦ P = {P1, P2, …, Pn}, the set consisting of all the processes in the
system.
◦ R = {R1, R2, …, Rm}, the multi-set consisting of all resource types
in the system.
◦ request edge – directed edge Pi  Rj
◦ assignment edge – directed edge Rj  Pi
Resource-Allocation Graph(RAG)
◦ Process
◦ Resource Type with 4 instances
◦ Pi requests instance of Rj
◦ Pi is holding an instance of Rj
Pi
Pi
Rj
Example of a Resource Allocation
Graph
Req
Hold
hold
hold
Req
hold
Resource Allocation Graph With A Deadlock
Graph With A Cycle But No Deadlock
Basic Facts
◦If graph contains no cycles  no deadlock.
◦If graph contains a cycle 
◦ if only one instance per resource type, then deadlock.
◦ if several instances per resource type, possibility of deadlock.
The Conditions for Deadlock
1. Mutual exclusion. Only one process may use a resource at a time. No process
may access a resource unit that has been allocated to another process.
2. Hold and wait. A process may hold allocated resources while awaiting assignment of other
resources.
3. No preemption. No resource can be forcibly removed from a process holding it.
The first three conditions are necessary but not sufficient for a deadlock to exist. For deadlock to
actually take place, a fourth condition is required:
4. Circular wait. A closed chain of processes exists, such that each process holds
at least one resource needed by the next process in the chain .
The Conditions for Deadlock (Cont…)
Possibility of Deadlock
1. Mutual exclusion
2. No preemption
3. Hold & Wait
Existence of Deadlock
1. Mutual exclusion
2. No preemption
3. Hold & Wait
4. Circular wait
HOW TO HANDLE DEADLOCKS – GENERAL
STRATEGIES
Methods for Handling Deadlocks:
1. Ignore Deadlocks: Most Operating systems do this!!
Ensure deadlock never occurs using either(Before)
2. Prevention Prevent any one of the 4 conditions from happening.
3. Avoidance Allow all deadlock conditions, but calculate cycles about to happen and stop
dangerous operations..
Allow deadlock to happen. This requires using both: (After)
4. Detection Know a deadlock has occurred.
5. Recovery Regain the resources.
Deadlock Prevention
Elimination of “Mutual Exclusion” Condition:
◦ Some resources, such as the tap drive and printer, are inherently non-
shareable. Note that shareable resources like read-only-file do not
require mutually exclusive access and thus cannot be involved in
deadlock.
Elimination of “Hold and Wait” Condition– must guarantee that whenever a process
requests a resource, it does not hold any other resources.
◦ Require process to request and be allocated all its resources before it begins
execution
◦ Or…allow process to request resources only when the process has none.
◦ Cons: Lower resource utilization
Restrain the ways request can be made.
Deadlock Prevention (Cont.)
Elimination of “No-preemption” Condition - If a process that is holding some
resources requests another resource that cannot be immediately allocated to
it, then all resources currently being held are released.
◦ Preempted resources are added to the list of resources for which the process is waiting.
◦ Process will be restarted only when it can regain its old resources, as well as the new ones
that it is requesting.
Elimination of “Circular Wait” Condition– impose a total ordering of all resource types, and
require that each process requests resources in an increasing order of enumeration.
◦ Then resource Ri precedes Rj in the ordering if i < j. Now suppose that two processes, A and B, are
deadlocked because A has acquired Ri and requested Rj, and B has acquired Rj and requested Ri. This
condition is impossible because it implies i < j and j < i.
Deadlock Avoidance
If we have prior knowledge of how resources will be requested, it's possible to determine if we
are entering an "unsafe" state.
Possible states are:
1. Deadlock No forward progress can be made.
2. Unsafe state A state that may allow deadlock.
3. Safe state A state is safe if a sequence of processes exist such that there are
enough resources for the first to finish, and as each finishes and releases its
resources there are enough for the next to finish.
The rule is simple: If a request allocation would cause an
unsafe state, do not honor that request.
NOTE: All deadlocks are unsafe, but all unsafe are NOT deadlocks.
NOTE: All deadlocks are unsafe, but all unsafe are NOT deadlocks.
SAFE
DEADLOCK
UNSAFE
Only with luck will
processes avoid
deadlock.
O.S. can avoid
deadlock.
Deadlock Avoidance
Let's assume a very simple model: each process declares its maximum needs. In
this case, algorithms exist that will ensure that no unsafe state is reached.
Maximum needs does NOT mean it must use that many resources – simply that it
might do so under some circumstances.
EXAMPLE:
There exists a total of 12 resources. Each resource is used exclusively by a process.
The current state looks like this:
In this example, < p1, p2, p0 >
is a workable sequence.
Suppose p2 requests and is
given one more resource.
What happens then?
Process Max Needs Allocated Current
Needs
P0 10 5 5
P1 4 2 2
P2 7 3 4
There are multiple instances of the resource
in these examples.
Deadlock Avoidance( Banker’s algo)
Banker’s Algorithm(Safty Algo)
1. Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively.
Initialize: Work = Available
Finish[i] = false; for i=1, 2, 3, 4….n
2. Find an i such that both
a) Finish[i] = false
b) Needi <= Work
if no such i exists goto step (4)
3. Work = Work + Allocation[i]
Finish[i] = true
goto step (2)
4. if Finish [i] = true for all i
then the system is in a safe state
Deadlock Detection
◦ Allow system to enter deadlock state
◦ Detection algorithm
◦ Recovery scheme
Deadlock Detection
Maintain wait-for graph
◦ Nodes are processes.
◦ Pi  Pj if Pi is waiting for Pj.
Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a
deadlock.
An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of
vertices in the graph.
Deadlock Detection
Detection algorithms depends on 2 factors:
1. How often is a deadlock likely to occurs?
2. How many processes will be affected by deadlock when it
happens?
Deadlock Recovery
So, the deadlock has occurred. Now, how do we get the resources back and gain forward progress?
PROCESS TERMINATION:
 Could delete all the processes in the deadlock -- this is expensive.
 Delete one at a time until deadlock is broken ( time consuming ).
 Select who to terminate based on priority, time executed, time to completion, needs for completion, or
depth of rollback
 In general, it's easier to preempt the resource, than to terminate the process.
RESOURCE PREEMPTION:
 Select a victim - which process and which resource to preempt.
 Rollback to previously defined "safe" state.
 Prevent one process from always being the one which is preempted ( starvation ).

More Related Content

What's hot

Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
Rakibul Rakib
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
Sonali Chauhan
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
Mukesh Chinta
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
Abhijith Reloaded
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
Kathirvel Ayyaswamy
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
vampugani
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
Harshana Madusanka Jayamaha
 
Deadlock
DeadlockDeadlock
Deadlock
Rajandeep Gill
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Syed Hassan Ali
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
Mukesh Chinta
 
Os Threads
Os ThreadsOs Threads
Os Threads
Salman Memon
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
Shakshi Ranawat
 
Mass Storage Structure
Mass Storage StructureMass Storage Structure
Mass Storage Structure
Vimalanathan D
 
Multiprogramming&timesharing
Multiprogramming&timesharingMultiprogramming&timesharing
Multiprogramming&timesharing
Tanuj Tyagi
 
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
cscarcas
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Deepika Balichwal
 
Scheduling
SchedulingScheduling
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
Mukesh Chinta
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Riya Choudhary
 

What's hot (20)

Process Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdfProcess Scheduling Algorithms.pdf
Process Scheduling Algorithms.pdf
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Deadlock
DeadlockDeadlock
Deadlock
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
 
Mass Storage Structure
Mass Storage StructureMass Storage Structure
Mass Storage Structure
 
Multiprogramming&timesharing
Multiprogramming&timesharingMultiprogramming&timesharing
Multiprogramming&timesharing
 
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
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Scheduling
SchedulingScheduling
Scheduling
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 

Similar to Ch 4 deadlock

4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
DishaDwivedi2
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
GRajendra
 
Os case study word
Os case study wordOs case study word
Os case study word
Dhol Yash
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
AUST
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
Gichelle Amon
 
OS K.Nishitha presentation on dead locks .pptx
OS K.Nishitha presentation on dead locks .pptxOS K.Nishitha presentation on dead locks .pptx
OS K.Nishitha presentation on dead locks .pptx
loksaikls
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
sheraz7288
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
rohassanie
 
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
svulasal
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
Nivedita Kasturi
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
marangburu42
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
IkhtiarUddinShaHin
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
Sakshi Tiwari
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
marangburu42
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
marangburu42
 
Deadlock
DeadlockDeadlock
Deadlock
Mahershi ACT
 
Deadlocks
DeadlocksDeadlocks
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
amadayshwan
 
Section07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.pptSection07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.ppt
jbri1395
 
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
MogilicharlaPavanKal
 

Similar to Ch 4 deadlock (20)

4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 
Os case study word
Os case study wordOs case study word
Os case study word
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
OS K.Nishitha presentation on dead locks .pptx
OS K.Nishitha presentation on dead locks .pptxOS K.Nishitha presentation on dead locks .pptx
OS K.Nishitha presentation on dead locks .pptx
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3FP 202 Chapter 2 - Part 3
FP 202 Chapter 2 - Part 3
 
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
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
Section07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.pptSection07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.ppt
 
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
TIPNGVN2
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
Neo4j
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
KAMESHS29
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Data structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdfData structures and Algorithms in Python.pdf
Data structures and Algorithms in Python.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
GraphSummit Singapore | Neo4j Product Vision & Roadmap - Q2 2024
 
RESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for studentsRESUME BUILDER APPLICATION Project for students
RESUME BUILDER APPLICATION Project for students
 

Ch 4 deadlock

  • 2. Deadlock EXAMPLES: 1. "It takes money to make money". 2. You can't get a job without experience; you can't get experience without a job. BACKGROUND: ◦ The cause of deadlocks: Each process needing what another process has. This results from sharing resources such as memory, devices, links. ◦ Under normal operation, a resource allocations proceed like this:: 1. Request a resource (suspend until available if necessary ). 2. Use the resource. 3. Release the resource
  • 3. What is Deadlock? for 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.
  • 4. Deadlock Bridge Crossing Example ◦ Traffic only in one direction. ◦ Each section of a bridge can be viewed as a resource. ◦ If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). ◦ Several cars may have to be backed up if a deadlock occurs. ◦ Starvation is possible.
  • 5. Deadlock ◦ Space is available for allocation of 200Kbytes, and the following sequence of events occur ◦ Deadlock occurs if both processes progress to their second request P1 . . . Request 80 Kbytes; … Request 60 Kbytes; P2 . . . Request 70 Kbytes; … Request 80 Kbytes;
  • 6. Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 1. Mutual exclusion: only one process at a time can use a resource 2. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes 3. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task 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.
  • 7. Resource-Allocation Graph ◦A set of vertices V and a set of edges E. ◦ V is partitioned into two types: ◦ P = {P1, P2, …, Pn}, the set consisting of all the processes in the system. ◦ R = {R1, R2, …, Rm}, the multi-set consisting of all resource types in the system. ◦ request edge – directed edge Pi  Rj ◦ assignment edge – directed edge Rj  Pi
  • 8. Resource-Allocation Graph(RAG) ◦ Process ◦ Resource Type with 4 instances ◦ Pi requests instance of Rj ◦ Pi is holding an instance of Rj Pi Pi Rj
  • 9. Example of a Resource Allocation Graph Req Hold hold hold Req hold
  • 10. Resource Allocation Graph With A Deadlock
  • 11. Graph With A Cycle But No Deadlock
  • 12. Basic Facts ◦If graph contains no cycles  no deadlock. ◦If graph contains a cycle  ◦ if only one instance per resource type, then deadlock. ◦ if several instances per resource type, possibility of deadlock.
  • 13. The Conditions for Deadlock 1. Mutual exclusion. Only one process may use a resource at a time. No process may access a resource unit that has been allocated to another process. 2. Hold and wait. A process may hold allocated resources while awaiting assignment of other resources. 3. No preemption. No resource can be forcibly removed from a process holding it. The first three conditions are necessary but not sufficient for a deadlock to exist. For deadlock to actually take place, a fourth condition is required: 4. Circular wait. A closed chain of processes exists, such that each process holds at least one resource needed by the next process in the chain .
  • 14. The Conditions for Deadlock (Cont…) Possibility of Deadlock 1. Mutual exclusion 2. No preemption 3. Hold & Wait Existence of Deadlock 1. Mutual exclusion 2. No preemption 3. Hold & Wait 4. Circular wait
  • 15. HOW TO HANDLE DEADLOCKS – GENERAL STRATEGIES Methods for Handling Deadlocks: 1. Ignore Deadlocks: Most Operating systems do this!! Ensure deadlock never occurs using either(Before) 2. Prevention Prevent any one of the 4 conditions from happening. 3. Avoidance Allow all deadlock conditions, but calculate cycles about to happen and stop dangerous operations.. Allow deadlock to happen. This requires using both: (After) 4. Detection Know a deadlock has occurred. 5. Recovery Regain the resources.
  • 16. Deadlock Prevention Elimination of “Mutual Exclusion” Condition: ◦ Some resources, such as the tap drive and printer, are inherently non- shareable. Note that shareable resources like read-only-file do not require mutually exclusive access and thus cannot be involved in deadlock. Elimination of “Hold and Wait” Condition– must guarantee that whenever a process requests a resource, it does not hold any other resources. ◦ Require process to request and be allocated all its resources before it begins execution ◦ Or…allow process to request resources only when the process has none. ◦ Cons: Lower resource utilization Restrain the ways request can be made.
  • 17. Deadlock Prevention (Cont.) Elimination of “No-preemption” Condition - If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. ◦ Preempted resources are added to the list of resources for which the process is waiting. ◦ Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. Elimination of “Circular Wait” Condition– impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. ◦ Then resource Ri precedes Rj in the ordering if i < j. Now suppose that two processes, A and B, are deadlocked because A has acquired Ri and requested Rj, and B has acquired Rj and requested Ri. This condition is impossible because it implies i < j and j < i.
  • 18. Deadlock Avoidance If we have prior knowledge of how resources will be requested, it's possible to determine if we are entering an "unsafe" state. Possible states are: 1. Deadlock No forward progress can be made. 2. Unsafe state A state that may allow deadlock. 3. Safe state A state is safe if a sequence of processes exist such that there are enough resources for the first to finish, and as each finishes and releases its resources there are enough for the next to finish. The rule is simple: If a request allocation would cause an unsafe state, do not honor that request. NOTE: All deadlocks are unsafe, but all unsafe are NOT deadlocks.
  • 19. NOTE: All deadlocks are unsafe, but all unsafe are NOT deadlocks. SAFE DEADLOCK UNSAFE Only with luck will processes avoid deadlock. O.S. can avoid deadlock. Deadlock Avoidance
  • 20. Let's assume a very simple model: each process declares its maximum needs. In this case, algorithms exist that will ensure that no unsafe state is reached. Maximum needs does NOT mean it must use that many resources – simply that it might do so under some circumstances. EXAMPLE: There exists a total of 12 resources. Each resource is used exclusively by a process. The current state looks like this: In this example, < p1, p2, p0 > is a workable sequence. Suppose p2 requests and is given one more resource. What happens then? Process Max Needs Allocated Current Needs P0 10 5 5 P1 4 2 2 P2 7 3 4 There are multiple instances of the resource in these examples. Deadlock Avoidance( Banker’s algo)
  • 21. Banker’s Algorithm(Safty Algo) 1. Let Work and Finish be vectors of length ‘m’ and ‘n’ respectively. Initialize: Work = Available Finish[i] = false; for i=1, 2, 3, 4….n 2. Find an i such that both a) Finish[i] = false b) Needi <= Work if no such i exists goto step (4) 3. Work = Work + Allocation[i] Finish[i] = true goto step (2) 4. if Finish [i] = true for all i then the system is in a safe state
  • 22. Deadlock Detection ◦ Allow system to enter deadlock state ◦ Detection algorithm ◦ Recovery scheme
  • 23. Deadlock Detection Maintain wait-for graph ◦ Nodes are processes. ◦ Pi  Pj if Pi is waiting for Pj. Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock. An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph.
  • 24. Deadlock Detection Detection algorithms depends on 2 factors: 1. How often is a deadlock likely to occurs? 2. How many processes will be affected by deadlock when it happens?
  • 25. Deadlock Recovery So, the deadlock has occurred. Now, how do we get the resources back and gain forward progress? PROCESS TERMINATION:  Could delete all the processes in the deadlock -- this is expensive.  Delete one at a time until deadlock is broken ( time consuming ).  Select who to terminate based on priority, time executed, time to completion, needs for completion, or depth of rollback  In general, it's easier to preempt the resource, than to terminate the process. RESOURCE PREEMPTION:  Select a victim - which process and which resource to preempt.  Rollback to previously defined "safe" state.  Prevent one process from always being the one which is preempted ( starvation ).