This document summarizes key concepts about deadlocks from Chapter 7 of the textbook "Operating System Concepts – 9th Edition" by Silberschatz, Galvin and Gagne. It defines the four conditions required for deadlock, describes methods for handling deadlocks including prevention, avoidance, detection and recovery, and provides examples to illustrate resource allocation graphs and the banker's algorithm for deadlock avoidance.
The Deadlock Problem
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
The Deadlock Problem
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
cpu scheduling bassically tell us about the outer structure or the managemnet of the computer tha how it is done ,it bassically tell us about how our cpu is scheduled.
cpu scheduling bassically tell us about the outer structure or the managemnet of the computer tha how it is done ,it bassically tell us about how our cpu is scheduled.
Senthilkanth,MCA..
The following ppt's full topic covers Operating System for BSc CS, BCA, MSc CS, MCA students..
1.Introduction
2.OS Structures
3.Process
4.Threads
5.CPU Scheduling
6.Process Synchronization
7.Dead Locks
8.Memory Management
9.Virtual Memory
10.File system Interface
11.File system implementation
12.Mass Storage System
13.IO Systems
14.Protection
15.Security
16.Distributed System Structure
17.Distributed File System
18.Distributed Co Ordination
19.Real Time System
20.Multimedia Systems
21.Linux
22.Windows
deadlocks operation systems explaining concepts in deadlocks which occur when a process or thread enters a waiting state because a requested system resource is held by another waiting process, which in turn is waiting for another resource held by another waiting process.
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
Combined Approach to Deadlock Handling
Lecture # 10-11 for deadlock operating system.pptRiaanSadiq
A deadlock is a state in a computer system where two or more processes are unable to proceed because each is waiting for the other to release a resource. This impasse leads to a standstill in the execution of programs, resulting in a halt of system operations. Deadlocks typically occur in multitasking or multi-process environments, where processes compete for shared resources such as memory, files, or hardware devices.
The deadlock scenario involves a cyclic waiting condition, where each process holds a resource and waits for another resource held by a different process. This circular dependency prevents any of the involved processes from making progress, causing the entire system to become unresponsive.
Key conditions for a deadlock to occur include mutual exclusion, where resources cannot be simultaneously shared; hold and wait, where a process holds resources while waiting for additional ones; no preemption, where resources cannot be forcibly taken away from a process; and circular wait, where a cycle of processes forms, each waiting for the next to release a resource.
Deadlock prevention and resolution strategies are crucial in system design to ensure efficient resource utilization and prevent the potential negative impacts of deadlocks on overall system performance.A deadlock is a state in a computer system where two or more processes are unable to proceed because each is waiting for the other to release a resource. This impasse leads to a standstill in the execution of programs, resulting in a halt of system operations. Deadlocks typically occur in multitasking or multi-process environments, where processes compete for shared resources such as memory, files, or hardware devices.
The deadlock scenario involves a cyclic waiting condition, where each process holds a resource and waits for another resource held by a different process. This circular dependency prevents any of the involved processes from making progress, causing the entire system to become unresponsive.
Key conditions for a deadlock to occur include mutual exclusion, where resources cannot be simultaneously shared; hold and wait, where a process holds resources while waiting for additional ones; no preemption, where resources cannot be forcibly taken away from a process; and circular wait, where a cycle of processes forms, each waiting for the next to release a resource.
Deadlock prevention and resolution strategies are crucial in system design to ensure efficient resource utilization and prevent the potential negative impacts of deadlocks on overall system performance.A deadlock is a state in a computer system where two or more processes are unable to proceed because each is waiting for the other to release a resource. This impasse leads to a standstill in the execution of programs, resulting in a halt of system operations.
Code reviews are vital for ensuring good code quality. They serve as one of our last lines of defense against bugs and subpar code reaching production.
Yet, they often turn into annoying tasks riddled with frustration, hostility, unclear feedback and lack of standards. How can we improve this crucial process?
In this session we will cover:
- The Art of Effective Code Reviews
- Streamlining the Review Process
- Elevating Reviews with Automated Tools
By the end of this presentation, you'll have the knowledge on how to organize and improve your code review proces
Zoom is a comprehensive platform designed to connect individuals and teams efficiently. With its user-friendly interface and powerful features, Zoom has become a go-to solution for virtual communication and collaboration. It offers a range of tools, including virtual meetings, team chat, VoIP phone systems, online whiteboards, and AI companions, to streamline workflows and enhance productivity.
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
Mobile App Development Company In Noida | Drona InfotechDrona Infotech
Looking for a reliable mobile app development company in Noida? Look no further than Drona Infotech. We specialize in creating customized apps for your business needs.
Visit Us For : https://www.dronainfotech.com/mobile-application-development/
Graspan: A Big Data System for Big Code AnalysisAftab Hussain
We built a disk-based parallel graph system, Graspan, that uses a novel edge-pair centric computation model to compute dynamic transitive closures on very large program graphs.
We implement context-sensitive pointer/alias and dataflow analyses on Graspan. An evaluation of these analyses on large codebases such as Linux shows that their Graspan implementations scale to millions of lines of code and are much simpler than their original implementations.
These analyses were used to augment the existing checkers; these augmented checkers found 132 new NULL pointer bugs and 1308 unnecessary NULL tests in Linux 4.4.0-rc5, PostgreSQL 8.3.9, and Apache httpd 2.2.18.
- Accepted in ASPLOS ‘17, Xi’an, China.
- Featured in the tutorial, Systemized Program Analyses: A Big Data Perspective on Static Analysis Scalability, ASPLOS ‘17.
- Invited for presentation at SoCal PLS ‘16.
- Invited for poster presentation at PLDI SRC ‘16.
Transform Your Communication with Cloud-Based IVR SolutionsTheSMSPoint
Discover the power of Cloud-Based IVR Solutions to streamline communication processes. Embrace scalability and cost-efficiency while enhancing customer experiences with features like automated call routing and voice recognition. Accessible from anywhere, these solutions integrate seamlessly with existing systems, providing real-time analytics for continuous improvement. Revolutionize your communication strategy today with Cloud-Based IVR Solutions. Learn more at: https://thesmspoint.com/channel/cloud-telephony
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
Quarkus Hidden and Forbidden ExtensionsMax Andersen
Quarkus has a vast extension ecosystem and is known for its subsonic and subatomic feature set. Some of these features are not as well known, and some extensions are less talked about, but that does not make them less interesting - quite the opposite.
Come join this talk to see some tips and tricks for using Quarkus and some of the lesser known features, extensions and development techniques.
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Łukasz Chruściel
No one wants their application to drag like a car stuck in the slow lane! Yet it’s all too common to encounter bumpy, pothole-filled solutions that slow the speed of any application. Symfony apps are not an exception.
In this talk, I will take you for a spin around the performance racetrack. We’ll explore common pitfalls - those hidden potholes on your application that can cause unexpected slowdowns. Learn how to spot these performance bumps early, and more importantly, how to navigate around them to keep your application running at top speed.
We will focus in particular on tuning your engine at the application level, making the right adjustments to ensure that your system responds like a well-oiled, high-performance race car.
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppGoogle
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-fusion-buddy-review
AI Fusion Buddy Review: Key Features
✅Create Stunning AI App Suite Fully Powered By Google's Latest AI technology, Gemini
✅Use Gemini to Build high-converting Converting Sales Video Scripts, ad copies, Trending Articles, blogs, etc.100% unique!
✅Create Ultra-HD graphics with a single keyword or phrase that commands 10x eyeballs!
✅Fully automated AI articles bulk generation!
✅Auto-post or schedule stunning AI content across all your accounts at once—WordPress, Facebook, LinkedIn, Blogger, and more.
✅With one keyword or URL, generate complete websites, landing pages, and more…
✅Automatically create & sell AI content, graphics, websites, landing pages, & all that gets you paid non-stop 24*7.
✅Pre-built High-Converting 100+ website Templates and 2000+ graphic templates logos, banners, and thumbnail images in Trending Niches.
✅Say goodbye to wasting time logging into multiple Chat GPT & AI Apps once & for all!
✅Save over $5000 per year and kick out dependency on third parties completely!
✅Brand New App: Not available anywhere else!
✅ Beginner-friendly!
✅ZERO upfront cost or any extra expenses
✅Risk-Free: 30-Day Money-Back Guarantee!
✅Commercial License included!
See My Other Reviews Article:
(1) AI Genie Review: https://sumonreview.com/ai-genie-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
#AIFusionBuddyReview,
#AIFusionBuddyFeatures,
#AIFusionBuddyPricing,
#AIFusionBuddyProsandCons,
#AIFusionBuddyTutorial,
#AIFusionBuddyUserExperience
#AIFusionBuddyforBeginners,
#AIFusionBuddyBenefits,
#AIFusionBuddyComparison,
#AIFusionBuddyInstallation,
#AIFusionBuddyRefundPolicy,
#AIFusionBuddyDemo,
#AIFusionBuddyMaintenanceFees,
#AIFusionBuddyNewbieFriendly,
#WhatIsAIFusionBuddy?,
#HowDoesAIFusionBuddyWorks
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxrickgrimesss22
Discover the essential features to incorporate in your Winzo clone app to boost business growth, enhance user engagement, and drive revenue. Learn how to create a compelling gaming experience that stands out in the competitive market.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
2. 7.2 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Chapter 7: Deadlocks
System Model
Deadlock Characterization
Methods for Handling Deadlocks
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Recovery from Deadlock
3. 7.3 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Chapter Objectives
To develop a description of deadlocks, which prevent
sets of concurrent processes from completing their
tasks
To present a number of different methods for
preventing or avoiding deadlocks in a computer
system
4. 7.4 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
System Model
System consists of resources
Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
Each resource type Ri has Wi instances.
Each process utilizes a resource as follows:
request
use
release
5. 7.5 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Deadlock Characterization
Mutual exclusion: only one process at a time can use a
resource
Hold and wait: a process holding at least one resource is
waiting to acquire additional resources held by other
processes
No preemption: a resource can be released only
voluntarily by the process holding it, after that process has
completed its task
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.
Deadlock can arise if four conditions hold simultaneously.
6. 7.6 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph
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 set consisting of all resource types
in the system
request edge – directed edge Pi → Rj
assignment edge – directed edge Rj → Pi
A set of vertices V and a set of edges E.
7. 7.7 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph (Cont.)
Process
Resource Type with 4 instances
Pi requests instance of Rj
Pi is holding an instance of Rj
Pi
Pi
Rj
Rj
8. 7.8 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example of a Resource Allocation Graph
9. 7.9 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource Allocation Graph With A Deadlock
10. 7.10 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Graph With A Cycle But No Deadlock
11. 7.11 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
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
12. 7.12 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Methods for Handling Deadlocks
Ensure that the system will never enter a deadlock
state:
Deadlock prevention
Deadlock avoidence
Allow the system to enter a deadlock state and then
recover
Ignore the problem and pretend that deadlocks never
occur in the system; used by most operating systems,
including UNIX
13. 7.13 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Deadlock Prevention
Mutual Exclusion – not required for sharable resources
(e.g., read-only files); must hold for non-sharable resources
Hold and Wait – 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
allocated to it.
Low resource utilization; starvation possible
Restrain the ways request can be made
14. 7.14 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Deadlock Prevention (Cont.)
No Preemption –
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
Circular Wait – impose a total ordering of all resource
types, and require that each process requests resources in
an increasing order of enumeration
15. 7.15 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Deadlock Avoidance
Simplest and most useful model requires that each process
declare the maximum number of resources of each type
that it may need
The deadlock-avoidance algorithm dynamically examines
the resource-allocation state to ensure that there can never
be a circular-wait condition
Resource-allocation state is defined by the number of
available and allocated resources, and the maximum
demands of the processes
Requires that the system has some additional a priori information
available
16. 7.16 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Safe State
When a process requests an available resource, system must
decide if immediate allocation leaves the system in a safe state
System is in safe state if there exists a sequence <P1, P2, …, Pn>
of ALL the processes in the systems such that for each Pi, the
resources that Pi can still request can be satisfied by currently
available resources + resources held by all the Pj, with j < I
That is:
If Pi resource needs are not immediately available, then Pi can
wait until all Pj have finished
When Pj is finished, Pi can obtain needed resources, execute,
return allocated resources, and terminate
When Pi terminates, Pi +1 can obtain its needed resources, and
so on
17. 7.17 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Basic Facts
If a system is in safe state ⇒ no deadlocks
If a system is in unsafe state ⇒ possibility of deadlock
Avoidance ⇒ ensure that a system will never enter an
unsafe state.
18. 7.18 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Safe, Unsafe, Deadlock State
19. 7.19 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Avoidance Algorithms
Single instance of a resource type
Use a resource-allocation graph
Multiple instances of a resource type
Use the banker’s algorithm
20. 7.20 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph Scheme
Claim edge Pi → Rj indicated that process Pj may request
resource Rj; represented by a dashed line
Claim edge converts to request edge when a process requests
a resource
Request edge converted to an assignment edge when the
resource is allocated to the process
When a resource is released by a process, assignment edge
reconverts to a claim edge
Resources must be claimed a priori in the system
21. 7.21 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph
22. 7.22 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Unsafe State In Resource-Allocation Graph
23. 7.23 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph Algorithm
Suppose that process Pi requests a resource Rj
The request can be granted only if converting the
request edge to an assignment edge does not result
in the formation of a cycle in the resource allocation
graph
24. 7.24 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Banker’s Algorithm
Multiple instances
Each process must a priori claim maximum use
When a process requests a resource it may have to wait
When a process gets all its resources it must return them in a
finite amount of time
25. 7.25 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Data Structures for the Banker’s Algorithm
Available: Vector of length m. If available [j] = k, there are k
instances of resource type Rj available
Max: n x m matrix. If Max [i,j] = k, then process Pi may request at
most k instances of resource type Rj
Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently
allocated k instances of Rj
Need: n x m matrix. If Need[i,j] = k, then Pi may need k more
instances of Rj to complete its task
Need [i,j] = Max[i,j] – Allocation [i,j]
Let n = number of processes, and m = number of resources types.
26. 7.26 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Safety Algorithm
1. Let Work and Finish be vectors of length m and n, respectively.
Initialize:
Work = Available
Finish [i] = false for i = 0, 1, …, n- 1
2. Find an i such that both:
(a) Finish [i] = false
(b) Needi ≤ Work
If no such i exists, go to step 4
3. Work = Work + Allocationi
Finish[i] = true
go to step 2
4. If Finish [i] == true for all i, then the system is in a safe state
27. 7.27 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Request Algorithm for Process Pi
Requesti = request vector for process Pi. If Requesti [j] = k then
process Pi wants k instances of resource type Rj
1. If Requesti ≤ Needi go to step 2. Otherwise, raise error
condition, since process has exceeded its maximum claim
2. If Requesti ≤ Available, go to step 3. Otherwise Pi must wait,
since resources are not available
3. Pretend to allocate requested resources to Pi by modifying the
state as follows:
Available = Available – Requesti;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
If safe ⇒ the resources are allocated to Pi
If unsafe ⇒ Pi must wait, and the old resource-allocation state
is restored
28. 7.28 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example of Banker’s Algorithm
5 processes P0 through P4;
3 resource types:
A (10 instances), B (5instances), and C (7 instances)
Snapshot at time T0:
Allocation Max Available
A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
29. 7.29 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example (Cont.)
The content of the matrix Need is defined to be Max – Allocation
Need
A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1
The system is in a safe state since the sequence < P1, P3, P4, P2, P0>
satisfies safety criteria
30. 7.30 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example: P1 Request (1,0,2)
Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2) ⇒ true
Allocation Need Available
A B C A B C A B C
P0 0 1 0 7 4 3 2 3 0
P1 3 0 2 0 2 0
P2 3 0 2 6 0 0
P3 2 1 1 0 1 1
P4 0 0 2 4 3 1
Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2>
satisfies safety requirement
Can request for (3,3,0) by P4 be granted?
Can request for (0,2,0) by P0 be granted?
31. 7.31 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Deadlock Detection
Allow system to enter deadlock state
Detection algorithm
Recovery scheme
32. 7.32 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Single Instance of Each Resource Type
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
33. 7.33 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Resource-Allocation Graph and Wait-for Graph
Resource-Allocation Graph Corresponding wait-for graph
34. 7.34 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Several Instances of a Resource Type
Available: A vector of length m indicates the number of
available resources of each type
Allocation: An n x m matrix defines the number of resources
of each type currently allocated to each process
Request: An n x m matrix indicates the current request of
each process. If Request [i][j] = k, then process Pi is
requesting k more instances of resource type Rj.
35. 7.35 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Detection Algorithm
1. Let Work and Finish be vectors of length m and n, respectively
Initialize:
(a) Work = Available
(b) For i = 1,2, …, n, if Allocationi ≠ 0, then
Finish[i] = false; otherwise, Finish[i] = true
2. Find an index i such that both:
(a) Finish[i] == false
(b) Requesti ≤ Work
If no such i exists, go to step 4
36. 7.36 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Detection Algorithm (Cont.)
3. Work = Work + Allocationi
Finish[i] = true
go to step 2
4. If Finish[i] == false, for some i, 1 ≤ i ≤ n, then the system is in
deadlock state. Moreover, if Finish[i] == false, then Pi is
deadlocked
Algorithm requires an order of O(m x n2
) operations to detect
whether the system is in deadlocked state
37. 7.37 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example of Detection Algorithm
Five processes P0 through P4;three resource types
A (7 instances), B (2 instances), and C (6 instances)
Snapshot at time T0:
Allocation Request Available
A B C A B C A B C
P0 0 1 0 0 0 0 0 0 0
P1 2 0 0 2 0 2
P2 3 0 3 0 0 0
P3 2 1 1 1 0 0
P4 0 0 2 0 0 2
Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i
38. 7.38 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Example (Cont.)
P2 requests an additional instance of type C
Request
A B C
P0 0 0 0
P1 2 0 2
P2 0 0 1
P3 1 0 0
P4 0 0 2
State of system?
Can reclaim resources held by process P0, but insufficient
resources to fulfill other processes; requests
Deadlock exists, consisting of processes P1, P2, P3, and P4
39. 7.39 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Detection-Algorithm Usage
When, and how often, to invoke depends on:
How often a deadlock is likely to occur?
How many processes will need to be rolled back?
one for each disjoint cycle
If detection algorithm is invoked arbitrarily, there may be many
cycles in the resource graph and so we would not be able to tell
which of the many deadlocked processes “caused” the deadlock.
40. 7.40 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Recovery from Deadlock: Process Termination
Abort all deadlocked processes
Abort one process at a time until the deadlock cycle is eliminated
In which order should we choose to abort?
1. Priority of the process
2. How long process has computed, and how much longer to
completion
3. Resources the process has used
4. Resources process needs to complete
5. How many processes will need to be terminated
6. Is process interactive or batch?
41. 7.41 Silberschatz, Galvin and GagneOperating System Concepts – 9th
Edition
Recovery from Deadlock: Resource Preemption
Selecting a victim – minimize cost
Rollback – return to some safe state, restart process for that
state
Starvation – same process may always be picked as victim,
include number of rollback in cost factor