SlideShare a Scribd company logo
1 of 18
UNIT IV
Deadlocks: System Model, Deadlock Characterization, Methods for Handling
Deadlocks, Deadlock Prevention, Deadlock Avoidance, Deadlock Detection,
Recovery from Deadlock
Introduction of
Deadlock in
Operating System
A process in operating systems uses different resources
and uses resources in the following way.
 1) Requests a resource
 2) Use the resource
 2) Releases the resource
Deadlock
 Deadlock is a situation where a set of processes are
blocked because each process is holding a resource and
waiting for another resource acquired by some other
process.
 Consider an example when two trains are coming
toward each other on the same track and there is only
one track, none of the trains can move once they are in
front of each other. A similar situation occurs in
operating systems when there are two or more
processes that hold some resources and wait for
resources held by other(s). For example, in the below
diagram, Process 1 is holding Resource 1 and waiting
for resource 2 which is acquired by process 2, and
process 2 is waiting for resource 1.
Deadlock
Deadlock
Characterization
Deadlock can arise if the following four conditions hold
simultaneously (Necessary Conditions)
 Mutual Exclusion: One or more than one resource are
non-shareable (Only one process can use at a time)
 Hold and Wait: A process is holding at least one
resource and waiting for resources.
 No Preemption: A resource cannot be taken from a
process unless the process releases the resource.
 Circular Wait: A set of processes are waiting for each
other in circular form.
Mutual
Exclusion
 There should be a resource that can only be held by one
process at a time. In the diagram below, there is a
single instance of Resource 1 and it is held by Process 1
only.
HoldandWait
 A process can hold multiple resources and still request
more resources from other processes which are holding
them. In the diagram given below, Process 2 holds
Resource 2 and Resource 3 and is requesting the
Resource 1 which is held by Process 1.
NoPreemption
 A resource cannot be preempted from a process by
force. A process can only release a resource voluntarily.
In the diagram below, Process 2 cannot preempt
Resource 1 from Process 1. It will only be released
when Process 1 relinquishes it voluntarily after its
execution is complete.
CircularWait
 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. 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.
Methodsfor
Handling
Deadlocks
 Deadlock Detection
Deadlock can be detected by the resource scheduler as it
keeps track of all the resources that are allocated to
different processes. After a deadlock is detected, it can be
handed using the given methods −
 All the processes that are involved in the deadlock are
terminated. This approach is not that useful as all the
progress made by the processes is destroyed.
 Resources can be preempted from some processes and
given to others until the deadlock situation is resolved.
Deadlock
Prevention
It is important to prevent a deadlock before it can occur. So, the system
checks each transaction before it is executed to make sure it does not
lead to deadlock. If there is even a slight possibility that a transaction
may lead to deadlock, it is never allowed to execute.
 Some deadlock prevention schemes that use timestamps in order to
make sure that a deadlock does not occur are given as follows −
• Wait - Die Scheme
• In the wait - die scheme, if a transaction T1 requests for a resource
that is held by transaction T2, one of the following two scenarios may
occur −
• TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in the system
earlier than T2, then it is allowed to wait for the resource which will
be free when T2 has completed its execution.
• TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came in the
system after T2, then T1 is killed. It is restarted later with the same
timestamp.
Deadlock
Prevention
Wound - Wait Scheme
• In the wound - wait scheme, if a transaction T1
requests for a resource that is held by transaction T2,
one of the following two possibilities may occur −
• TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in
the system earlier than T2, then it is allowed to roll back
T2 or wound T2. Then T1 takes the resource and
completes its execution. T2 is later restarted with the
same timestamp.
• TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came
in the system after T2, then it is allowed to wait for the
resource which will be free when T2 has completed its
execution.
Deadlock
Avoidance
 It is better to avoid a deadlock rather than take measures
after the deadlock has occurred. The wait for graph can be
used for deadlock avoidance. Wait for graph
 The wait for graph shows the relationship between the
resources and transactions. If a transaction requests a
resource or if it already holds a resource, it is visible as an
edge on the wait for graph. If the wait for graph contains a
cycle, then there may be a deadlock in the system,
otherwise not.
Deadlock
Avoidance
 Ostrich Algorithm
 The ostrich algorithm means that the deadlock is
simply ignored and it is assumed that it will never
occur. This is done because in some systems the cost of
handling the deadlock is much higher than simply
ignoring it as it occurs very rarely. So, it is simply
assumed that the deadlock will never occur and the
system is rebooted if it occurs by any chance.
Recoveryfrom
Deadlock
When a Deadlock Detection Algorithm determines that a
deadlock has occurred in the system, the system must
recover from that deadlock. There are two approaches of
breaking a Deadlock:
1. Process Termination:
 To eliminate the deadlock, we can simply kill one or more
processes. For this, we use two methods:
(a). Abort all the Deadlocked Processes:
Aborting all the processes will certainly break the deadlock,
but with a great expenses. The deadlocked processes may
have computed for a long time and the result of those partial
computations must be discarded and there is a probability to
recalculate them later.
Recoveryfrom
Deadlock
(b). Abort one process at a time untill deadlock is
eliminated:
Abort one deadlocked process at a time, untill deadlock
cycle is eliminated from the system. Due to this method,
there may be considerable overhead, because after
aborting each process, we have to run deadlock detection
algorithm to check whether any processes are still
deadlocked.
Recoveryfrom
Deadlock
2. Resource Preemption:
To eliminate deadlocks using resource preemption, we
preepmt some resources from processes and give those
resources to other processes. This method will raise three
issues –
(a). Selecting a victim:
We must determine which resources and which
processes are to be preempted and also the
order to minimize the cost.
Recoveryfrom
Deadlock
(b). Rollback:
We must determine what should be done with the process
from which resources are preempted. One simple idea is
total rollback. That means abort the process and restart
it.
(c). Starvation:
In a system, it may happen that same process is always
picked as a victim. As a result, that process will never
complete its designated task. This situation is called
Starvation and must be avoided. One solution is that a
process must be picked as a victim only a finite number
of times.

More Related Content

What's hot (18)

Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
Chapter 7
Chapter 7Chapter 7
Chapter 7
 
Concurrent process
Concurrent processConcurrent process
Concurrent process
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Rtos concepts
Rtos conceptsRtos concepts
Rtos concepts
 
process management
 process management process management
process management
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Lecture 2 process
Lecture 2   processLecture 2   process
Lecture 2 process
 
Real Time Operating Systems
Real Time Operating SystemsReal Time Operating Systems
Real Time Operating Systems
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
Process threads operating system.
Process threads operating system.Process threads operating system.
Process threads operating system.
 
RTOS
RTOSRTOS
RTOS
 
File system and Deadlocks
File system and DeadlocksFile system and Deadlocks
File system and Deadlocks
 
Lecture 5 process concept
Lecture 5   process conceptLecture 5   process concept
Lecture 5 process concept
 
Real time-embedded-system-lec-02
Real time-embedded-system-lec-02Real time-embedded-system-lec-02
Real time-embedded-system-lec-02
 
Chapter 19 - Real Time Systems
Chapter 19 - Real Time SystemsChapter 19 - Real Time Systems
Chapter 19 - Real Time Systems
 

Similar to Unit iv: Deadlocks

Similar to Unit iv: Deadlocks (20)

Deadlock in operating systems
Deadlock in operating systemsDeadlock in operating systems
Deadlock in operating systems
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
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)
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
deadlock handling
deadlock handlingdeadlock handling
deadlock handling
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx4.3 Deadlock [Autosaved].pptx
4.3 Deadlock [Autosaved].pptx
 
Deadlockpresentation.pptx
Deadlockpresentation.pptxDeadlockpresentation.pptx
Deadlockpresentation.pptx
 
Deadlock
DeadlockDeadlock
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
 
Deadlock in database
Deadlock in databaseDeadlock in database
Deadlock in database
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
Deadlock
DeadlockDeadlock
Deadlock
 
Improved Deadlock Prevention Algorithms in Distributed Systems
Improved Deadlock Prevention Algorithms in Distributed SystemsImproved Deadlock Prevention Algorithms in Distributed Systems
Improved Deadlock Prevention Algorithms in Distributed Systems
 
deadlock
deadlockdeadlock
deadlock
 

More from Arnav Chowdhury

Startup Funding and Strategies for Future
Startup Funding and Strategies for FutureStartup Funding and Strategies for Future
Startup Funding and Strategies for FutureArnav Chowdhury
 
Marketing Management Introduction.pptx
Marketing Management Introduction.pptxMarketing Management Introduction.pptx
Marketing Management Introduction.pptxArnav Chowdhury
 
Marketing Management Product.pptx
Marketing Management Product.pptxMarketing Management Product.pptx
Marketing Management Product.pptxArnav Chowdhury
 
Institutional Support to Entrepreneurship
Institutional Support to EntrepreneurshipInstitutional Support to Entrepreneurship
Institutional Support to EntrepreneurshipArnav Chowdhury
 
New Venture Expansion and Exit Strategies
New Venture Expansion and Exit StrategiesNew Venture Expansion and Exit Strategies
New Venture Expansion and Exit StrategiesArnav Chowdhury
 
Creating a Business Plan
Creating a Business PlanCreating a Business Plan
Creating a Business PlanArnav Chowdhury
 
Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)Arnav Chowdhury
 
Business Research Methods (Introduction)
Business Research Methods (Introduction)Business Research Methods (Introduction)
Business Research Methods (Introduction)Arnav Chowdhury
 
Planning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial VenturePlanning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial VentureArnav Chowdhury
 
Fundamentals of Entrepreneurship
Fundamentals of EntrepreneurshipFundamentals of Entrepreneurship
Fundamentals of EntrepreneurshipArnav Chowdhury
 
Unit v: Cyber Safety Mechanism
Unit v: Cyber Safety MechanismUnit v: Cyber Safety Mechanism
Unit v: Cyber Safety MechanismArnav Chowdhury
 
UNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement StrategiesUNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement StrategiesArnav Chowdhury
 
Unit iii: Common Hacking Techniques
Unit iii: Common Hacking TechniquesUnit iii: Common Hacking Techniques
Unit iii: Common Hacking TechniquesArnav Chowdhury
 
Information Technology and Modern Gadgets
Information Technology and Modern GadgetsInformation Technology and Modern Gadgets
Information Technology and Modern GadgetsArnav Chowdhury
 

More from Arnav Chowdhury (20)

Startup Funding and Strategies for Future
Startup Funding and Strategies for FutureStartup Funding and Strategies for Future
Startup Funding and Strategies for Future
 
Marketing Management Introduction.pptx
Marketing Management Introduction.pptxMarketing Management Introduction.pptx
Marketing Management Introduction.pptx
 
Marketing Management Product.pptx
Marketing Management Product.pptxMarketing Management Product.pptx
Marketing Management Product.pptx
 
Institutional Support to Entrepreneurship
Institutional Support to EntrepreneurshipInstitutional Support to Entrepreneurship
Institutional Support to Entrepreneurship
 
New Venture Expansion and Exit Strategies
New Venture Expansion and Exit StrategiesNew Venture Expansion and Exit Strategies
New Venture Expansion and Exit Strategies
 
Creating a Business Plan
Creating a Business PlanCreating a Business Plan
Creating a Business Plan
 
Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)Business Research Methodology ( Data Collection)
Business Research Methodology ( Data Collection)
 
Business Research Methods (Introduction)
Business Research Methods (Introduction)Business Research Methods (Introduction)
Business Research Methods (Introduction)
 
Planning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial VenturePlanning and organizing Entrepreneurial Venture
Planning and organizing Entrepreneurial Venture
 
Fundamentals of Entrepreneurship
Fundamentals of EntrepreneurshipFundamentals of Entrepreneurship
Fundamentals of Entrepreneurship
 
ICT tools in Education
ICT tools in EducationICT tools in Education
ICT tools in Education
 
Unit v: Cyber Safety Mechanism
Unit v: Cyber Safety MechanismUnit v: Cyber Safety Mechanism
Unit v: Cyber Safety Mechanism
 
UNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement StrategiesUNIT IV:Security Measurement Strategies
UNIT IV:Security Measurement Strategies
 
Unit iii: Common Hacking Techniques
Unit iii: Common Hacking TechniquesUnit iii: Common Hacking Techniques
Unit iii: Common Hacking Techniques
 
Cyber Crime
Cyber CrimeCyber Crime
Cyber Crime
 
Information Technology and Modern Gadgets
Information Technology and Modern GadgetsInformation Technology and Modern Gadgets
Information Technology and Modern Gadgets
 
Unit iv FMIS
Unit iv FMISUnit iv FMIS
Unit iv FMIS
 
Unit iii FMIS
Unit iii FMISUnit iii FMIS
Unit iii FMIS
 
Unit ii FMIS
Unit ii FMISUnit ii FMIS
Unit ii FMIS
 
Unit iv graphics
Unit iv  graphicsUnit iv  graphics
Unit iv graphics
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Unit iv: Deadlocks

  • 1. UNIT IV Deadlocks: System Model, Deadlock Characterization, Methods for Handling Deadlocks, Deadlock Prevention, Deadlock Avoidance, Deadlock Detection, Recovery from Deadlock
  • 2. Introduction of Deadlock in Operating System A process in operating systems uses different resources and uses resources in the following way.  1) Requests a resource  2) Use the resource  2) Releases the resource
  • 3. Deadlock  Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process.  Consider an example when two trains are coming toward each other on the same track and there is only one track, none of the trains can move once they are in front of each other. A similar situation occurs in operating systems when there are two or more processes that hold some resources and wait for resources held by other(s). For example, in the below diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is acquired by process 2, and process 2 is waiting for resource 1.
  • 5. Deadlock Characterization Deadlock can arise if the following four conditions hold simultaneously (Necessary Conditions)  Mutual Exclusion: One or more than one resource are non-shareable (Only one process can use at a time)  Hold and Wait: A process is holding at least one resource and waiting for resources.  No Preemption: A resource cannot be taken from a process unless the process releases the resource.  Circular Wait: A set of processes are waiting for each other in circular form.
  • 6. Mutual Exclusion  There should be a resource that can only be held by one process at a time. In the diagram below, there is a single instance of Resource 1 and it is held by Process 1 only.
  • 7. HoldandWait  A process can hold multiple resources and still request more resources from other processes which are holding them. In the diagram given below, Process 2 holds Resource 2 and Resource 3 and is requesting the Resource 1 which is held by Process 1.
  • 8. NoPreemption  A resource cannot be preempted from a process by force. A process can only release a resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from Process 1. It will only be released when Process 1 relinquishes it voluntarily after its execution is complete.
  • 9. CircularWait  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. 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.
  • 10. Methodsfor Handling Deadlocks  Deadlock Detection Deadlock can be detected by the resource scheduler as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be handed using the given methods −  All the processes that are involved in the deadlock are terminated. This approach is not that useful as all the progress made by the processes is destroyed.  Resources can be preempted from some processes and given to others until the deadlock situation is resolved.
  • 11. Deadlock Prevention It is important to prevent a deadlock before it can occur. So, the system checks each transaction before it is executed to make sure it does not lead to deadlock. If there is even a slight possibility that a transaction may lead to deadlock, it is never allowed to execute.  Some deadlock prevention schemes that use timestamps in order to make sure that a deadlock does not occur are given as follows − • Wait - Die Scheme • In the wait - die scheme, if a transaction T1 requests for a resource that is held by transaction T2, one of the following two scenarios may occur − • TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in the system earlier than T2, then it is allowed to wait for the resource which will be free when T2 has completed its execution. • TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came in the system after T2, then T1 is killed. It is restarted later with the same timestamp.
  • 12. Deadlock Prevention Wound - Wait Scheme • In the wound - wait scheme, if a transaction T1 requests for a resource that is held by transaction T2, one of the following two possibilities may occur − • TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in the system earlier than T2, then it is allowed to roll back T2 or wound T2. Then T1 takes the resource and completes its execution. T2 is later restarted with the same timestamp. • TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came in the system after T2, then it is allowed to wait for the resource which will be free when T2 has completed its execution.
  • 13. Deadlock Avoidance  It is better to avoid a deadlock rather than take measures after the deadlock has occurred. The wait for graph can be used for deadlock avoidance. Wait for graph  The wait for graph shows the relationship between the resources and transactions. If a transaction requests a resource or if it already holds a resource, it is visible as an edge on the wait for graph. If the wait for graph contains a cycle, then there may be a deadlock in the system, otherwise not.
  • 14. Deadlock Avoidance  Ostrich Algorithm  The ostrich algorithm means that the deadlock is simply ignored and it is assumed that it will never occur. This is done because in some systems the cost of handling the deadlock is much higher than simply ignoring it as it occurs very rarely. So, it is simply assumed that the deadlock will never occur and the system is rebooted if it occurs by any chance.
  • 15. Recoveryfrom Deadlock When a Deadlock Detection Algorithm determines that a deadlock has occurred in the system, the system must recover from that deadlock. There are two approaches of breaking a Deadlock: 1. Process Termination:  To eliminate the deadlock, we can simply kill one or more processes. For this, we use two methods: (a). Abort all the Deadlocked Processes: Aborting all the processes will certainly break the deadlock, but with a great expenses. The deadlocked processes may have computed for a long time and the result of those partial computations must be discarded and there is a probability to recalculate them later.
  • 16. Recoveryfrom Deadlock (b). Abort one process at a time untill deadlock is eliminated: Abort one deadlocked process at a time, untill deadlock cycle is eliminated from the system. Due to this method, there may be considerable overhead, because after aborting each process, we have to run deadlock detection algorithm to check whether any processes are still deadlocked.
  • 17. Recoveryfrom Deadlock 2. Resource Preemption: To eliminate deadlocks using resource preemption, we preepmt some resources from processes and give those resources to other processes. This method will raise three issues – (a). Selecting a victim: We must determine which resources and which processes are to be preempted and also the order to minimize the cost.
  • 18. Recoveryfrom Deadlock (b). Rollback: We must determine what should be done with the process from which resources are preempted. One simple idea is total rollback. That means abort the process and restart it. (c). Starvation: In a system, it may happen that same process is always picked as a victim. As a result, that process will never complete its designated task. This situation is called Starvation and must be avoided. One solution is that a process must be picked as a victim only a finite number of times.