SlideShare a Scribd company logo
1 of 19
Deadlocks
A 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.
Mahershi Bhavsar
160160107005
Operating Systems
Necessary Conditions
A deadlock situation can arise if the following conditions hold simultaneously in a system.
• Mutual Exclusion:
• Hold and Wait:
• No Pre-emption:
• Circular Wait:
At least one resource must be held in a non sharable mode, that is, only one process at
a time can access the resource.
A process must be holding at least one resource while waiting to acquire additional
resource.
Resources cannot be pre-empted. A resource can only be released voluntarily by the
process holding it.
A set of waiting processes must exist such that each process is waiting for a resource
already acquired by some other process in the set.
If all the four conditions holds true, deadlock occurs.
Resource Allocation Graph
A resource allocation graph tracks which resource is hold by what process and which process is
waiting for a resource of a particular type. It is a very powerful and simple tool to illustrate how a set of
processes can deadlock.
• If a process is using a resource, an arrow is drawn from the resource
node to the process node.
• If a process is requesting a resource, an arrow is drawn from the process
node to resource node.
Resource Allocation Graph
If there is a cycle in the Resource Allocation Graph and each resource in the cycle provides only one
instance, then the process will deadlock.
In the given example, a deadlock occurs.
Process 1 waits for a resource already held by Process 3 and
Process 3 waits for a resource held by Process 2. Further,
Process 2 is waiting for a resource held by Process 1.
In the given example, only one instance of each resource is
considered. In real life there may be more than one instances
and the situation completely differs.
Methods for Handling Deadlocks
Deadlocks can be dealt with by one of the three ways stated below:
1. Using a protocol to ensure never entering a deadlock i.e. deadlock avoidance or prevention.
2. Detect and recover from a deadlocked situation.
3. Pretension. Pretend that deadlocks never occur in the system. (More like faith in God)
Deadlock Prevention
Deadlock can be prevented by preventing any one of the four necessary conditions for deadlock from
holding true.
1. Mutual Exclusion:
2. Hold and Wait:
It is not possible to prevent mutual exclusion because some resource needs to be non –
sharable, such as printer.
To ensure this condition doesn’t hold true, we must make sure a process doesn’t hold a
resource while requesting another. All the required resources must be requested and
allocated before the execution of the process begins. This also leads to wastage of
resources that remain idle until used but yet already allocated. Another protocol allows a
process to request resources only when it has none. Before a process requests
additional resources, it must release all currently allocated resources.
3. No Pre-emption:
4. Circular Wait:
To prevent this condition, if a process is holding some resource and requests additional
resources that cannot be immediately delivered, then all the resources being currently
held are pre-empted. These pre-empted resources are added to the list of resources
the process is waiting for. This protocol is often applied to resources whose state can
be easily saved and restored later.
Each resource will be assigned a number. A process can request resources only in the
increasing order or numbering. This ensures no request leads to a loop in the resource
allocation graph.
Deadlock Avoidance
Deadlock prevention is an efficient way to prevent deadlock but not efficient utilization of resources. It
leads to low device utilization and reduced system throughput.
An alternative method is to avoid deadlocks by having additional information of resources requested
and allocated. The simplest and most useful model requires each process to state maximum number
of resources of each type will it require.
Safe State:
A state of system is safe if it can allocate resource to each process in a certain order and still prevent
a deadlock.
Banker’s Algorithm is used to avoid deadlock. It confirms the system to be in safe system if the
requested resources are allocated.
Banker’s Algorithm
• An algorithm to avoid deadlocks
• When a process enters the system, it must declare the maximum instances of each type of
resource it may need. This number may not exceed the total number of resources of a particular
type in the system.
• Several data structures are maintained to implement this algorithm.
1. Available:
2. Max:
A vector of length m indicates the number of available resources. (A vector is a container type
in programming languages, it basically acts as dynamic array).
A v a i l a b l e [ j ] = k
k instances of resource type Rj are available.
A matrix (n x m) that defines maximum demand of each process.
M a x [ i ] [ j ] = k
Process Pi may request at most k instances of Rj
3. Allocation:
4. Max:
A matrix (n x m) that defines the number of allocation of each type of resource currently
allocated to a process.
A l l o c a t i o n [ i ] [ j ] = k
k instances of Rj are allocated to Pi
A matrix (n x m) that defines remaining resource need of each process.
N e e d [ i ] [ j ] = k
Pi may need k instances if Rj
Request Resource Algorithm:
1. If R e q u e s t i ≤ N e e d i , go to step 2. Otherwise, process exceeded its maximum claim.
2. If R e q u e s t i ≤ A v a i l a b l e i , go to step 3. Otherwise, Pi must wait, since resources are not available.
3. Pretend to allocate resource to check for resulting state.
A v a i l a b l e = A v a i l a b l e – R e q u e s t i
A l l o c a t i o n i = A l l o c a t i o n i + R e q u e s t
N e e d i = N e e d i – R e q u e s t i
If the resulting resource state is safe, the transaction is completed.
Process Allocation Max Available Need
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Illustration of Banker’s Algorithm
Let the system currently be in the state shown. Suppose now P1 requests one additional instance of resource A
and two additional instances of resource C, so R e q u e s t i = ( 1 , 0 , 2 ) .
We first check that R e q u e s t i ≤ A v a i l a b l e , that is ( 1 , 0 , 2 ) ≤ ( 3 , 3 , 2 ) which is true. We then pretend to
allocate the requested resources leading to a new state as follows
The obtained state is safe, hence we can immediately grant the newly requested resources to the process.
However a further request of (3,3,0) by P4 cannot be granted, since the resources are not available.
Safe State is determined by viewing all positive values in Available column.
Process Allocation Max Available Need
A B C A B C A B C A B C
P0 0 1 0 7 5 3 2 3 0 7 4 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Deadlock Detection
If a system does not provide deadlock avoidance or deadlock prevention, it must provide
• An algorithm to examine the state of the system, deadlock detection.
• An algorithm to recover from deadlock.
Deadlock can be easily detected using the resource allocation graph. If a single instance of resources are present,
deadlock can be detected by a presence of a cycle in the resource allocation graph.
For a system with several instances of a resource type, this method is not sufficient. An algorithm is designed to
detect deadlock in system with multiple instances of resources of a type.
The algorithm is similar to Banker’s Algorithm. It uses several data structures such as Available, Allocation and
Request.
The working of algorithm is shown below.
1. Let Work and Finish be vectors of length m and n respectively.
Work = Available. (initialization)
if A llocation i ≠ 0 , F in ish [i] = false
E lse, F in ish [i] = tru e
2. Find an index i such that
Finish[i] == false
Req u est i ≤ Work
if no such I exists, go to step 4.
3 . Work = Work + A llocation i
F in ish [i] = tru e
Go to Step 2.
4. If F in ish [i] == false , then the system is in a deadlocked state.
Deadlock Recovery
When a detection algorithm detects a deadlock, deadlock is manually or automatically handled to recover the safe
state of the system. There are two options of breaking a deadlock, abort one or more processes or to pre-empt
some resources.
Process Termination
Abort all deadlocked processes:
This method does break the deadlock but with a great expense. This method involves terminating all the processes
involved in the deadlock state.
Abort one process at a time until deadlock cycle is eliminated:
This method is more efficient than terminating all the processes. A deadlock detection algorithm is implemented to
determine which process to be terminated. Processes whose termination incurs minimum cost are terminated.
Resource Pre-emption
Successive pre-emption of resources to deal with deadlock. Three issues needs to be addressed in
this method.
1. Selecting a victim:
2. Rollback:
3. Starvation:
Selection of the resource to be pre-empted. Also involves determining the order of pre-
emption to minimize the cost. Cost factor includes various parameters such as number
of resources a deadlocked process holds or the mount of time the process has
consumed so far.
A process whose resource are pre-empted is rolled back up to a safe state from where
it can restart its execution.
Selecting victim based on cost parameters lead to starvation of the most expensive
process as it is always picked as the victim. The solution to prevent starvation is to
include number of roll backs for a process in the cost factor. A process must be chosen
as victim accordingly.
Mahershi Bhavsar
160160107005
Operating Systems

More Related Content

What's hot

Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & preventionIkhtiarUddinShaHin
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingTamannaSharma70
 
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...Wakil Kumar
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlockwahab13
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock GalvinSonali Chauhan
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systemsRai University
 
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Shayek Parvez
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lockKaram Munir Butt
 

What's hot (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networking
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Bankers
BankersBankers
Bankers
 
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...Deadlock- System model, resource types, deadlock problem, deadlock characteri...
Deadlock- System model, resource types, deadlock problem, deadlock characteri...
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
O ssvv62015
O ssvv62015O ssvv62015
O ssvv62015
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock
DeadlockDeadlock
Deadlock
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
 
Deadlock
DeadlockDeadlock
Deadlock
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Operating system - Deadlock
Operating system - DeadlockOperating system - Deadlock
Operating system - Deadlock
 

Similar to Deadlock

osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxBhaskar271887
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemEktaVaswani2
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinalmarangburu42
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456marangburu42
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)WajeehaBaig
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptxshreesha16
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.pptKAnurag2
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approachrahulmonikasharma
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approachrahulmonikasharma
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoorWani Zahoor
 
osvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdfosvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdfamadayshwan
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232marangburu42
 

Similar to Deadlock (20)

osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
Deadlocks prefinal
Deadlocks prefinalDeadlocks prefinal
Deadlocks prefinal
 
Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456Deadlocksprefinal 161014115456
Deadlocksprefinal 161014115456
 
Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)Unit 3 part 2(DEADLOCK)
Unit 3 part 2(DEADLOCK)
 
OS 7.pptx
OS 7.pptxOS 7.pptx
OS 7.pptx
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
 
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified ApproachImplementation of Banker’s Algorithm Using Dynamic Modified Approach
Implementation of Banker’s Algorithm Using Dynamic Modified Approach
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
Module3
Module3Module3
Module3
 
Os unit 4
Os unit 4Os unit 4
Os unit 4
 
Deadlocks by wani zahoor
Deadlocks by wani zahoorDeadlocks by wani zahoor
Deadlocks by wani zahoor
 
osvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdfosvishal-160830131208 (1).pdf
osvishal-160830131208 (1).pdf
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 

Recently uploaded

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 

Recently uploaded (20)

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 

Deadlock

  • 1. Deadlocks A 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. Mahershi Bhavsar 160160107005 Operating Systems
  • 2. Necessary Conditions A deadlock situation can arise if the following conditions hold simultaneously in a system. • Mutual Exclusion: • Hold and Wait: • No Pre-emption: • Circular Wait: At least one resource must be held in a non sharable mode, that is, only one process at a time can access the resource. A process must be holding at least one resource while waiting to acquire additional resource. Resources cannot be pre-empted. A resource can only be released voluntarily by the process holding it. A set of waiting processes must exist such that each process is waiting for a resource already acquired by some other process in the set. If all the four conditions holds true, deadlock occurs.
  • 3. Resource Allocation Graph A resource allocation graph tracks which resource is hold by what process and which process is waiting for a resource of a particular type. It is a very powerful and simple tool to illustrate how a set of processes can deadlock. • If a process is using a resource, an arrow is drawn from the resource node to the process node. • If a process is requesting a resource, an arrow is drawn from the process node to resource node. Resource Allocation Graph
  • 4. If there is a cycle in the Resource Allocation Graph and each resource in the cycle provides only one instance, then the process will deadlock. In the given example, a deadlock occurs. Process 1 waits for a resource already held by Process 3 and Process 3 waits for a resource held by Process 2. Further, Process 2 is waiting for a resource held by Process 1. In the given example, only one instance of each resource is considered. In real life there may be more than one instances and the situation completely differs.
  • 5. Methods for Handling Deadlocks Deadlocks can be dealt with by one of the three ways stated below: 1. Using a protocol to ensure never entering a deadlock i.e. deadlock avoidance or prevention. 2. Detect and recover from a deadlocked situation. 3. Pretension. Pretend that deadlocks never occur in the system. (More like faith in God)
  • 6. Deadlock Prevention Deadlock can be prevented by preventing any one of the four necessary conditions for deadlock from holding true. 1. Mutual Exclusion: 2. Hold and Wait: It is not possible to prevent mutual exclusion because some resource needs to be non – sharable, such as printer. To ensure this condition doesn’t hold true, we must make sure a process doesn’t hold a resource while requesting another. All the required resources must be requested and allocated before the execution of the process begins. This also leads to wastage of resources that remain idle until used but yet already allocated. Another protocol allows a process to request resources only when it has none. Before a process requests additional resources, it must release all currently allocated resources.
  • 7. 3. No Pre-emption: 4. Circular Wait: To prevent this condition, if a process is holding some resource and requests additional resources that cannot be immediately delivered, then all the resources being currently held are pre-empted. These pre-empted resources are added to the list of resources the process is waiting for. This protocol is often applied to resources whose state can be easily saved and restored later. Each resource will be assigned a number. A process can request resources only in the increasing order or numbering. This ensures no request leads to a loop in the resource allocation graph.
  • 8. Deadlock Avoidance Deadlock prevention is an efficient way to prevent deadlock but not efficient utilization of resources. It leads to low device utilization and reduced system throughput. An alternative method is to avoid deadlocks by having additional information of resources requested and allocated. The simplest and most useful model requires each process to state maximum number of resources of each type will it require. Safe State: A state of system is safe if it can allocate resource to each process in a certain order and still prevent a deadlock. Banker’s Algorithm is used to avoid deadlock. It confirms the system to be in safe system if the requested resources are allocated.
  • 9. Banker’s Algorithm • An algorithm to avoid deadlocks • When a process enters the system, it must declare the maximum instances of each type of resource it may need. This number may not exceed the total number of resources of a particular type in the system. • Several data structures are maintained to implement this algorithm. 1. Available: 2. Max: A vector of length m indicates the number of available resources. (A vector is a container type in programming languages, it basically acts as dynamic array). A v a i l a b l e [ j ] = k k instances of resource type Rj are available. A matrix (n x m) that defines maximum demand of each process. M a x [ i ] [ j ] = k Process Pi may request at most k instances of Rj
  • 10. 3. Allocation: 4. Max: A matrix (n x m) that defines the number of allocation of each type of resource currently allocated to a process. A l l o c a t i o n [ i ] [ j ] = k k instances of Rj are allocated to Pi A matrix (n x m) that defines remaining resource need of each process. N e e d [ i ] [ j ] = k Pi may need k instances if Rj
  • 11. Request Resource Algorithm: 1. If R e q u e s t i ≤ N e e d i , go to step 2. Otherwise, process exceeded its maximum claim. 2. If R e q u e s t i ≤ A v a i l a b l e i , go to step 3. Otherwise, Pi must wait, since resources are not available. 3. Pretend to allocate resource to check for resulting state. A v a i l a b l e = A v a i l a b l e – R e q u e s t i A l l o c a t i o n i = A l l o c a t i o n i + R e q u e s t N e e d i = N e e d i – R e q u e s t i If the resulting resource state is safe, the transaction is completed.
  • 12. Process Allocation Max Available Need A B C A B C A B C A B C P0 0 1 0 7 5 3 3 3 2 7 4 3 P1 2 0 0 3 2 2 1 2 2 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1 Illustration of Banker’s Algorithm Let the system currently be in the state shown. Suppose now P1 requests one additional instance of resource A and two additional instances of resource C, so R e q u e s t i = ( 1 , 0 , 2 ) . We first check that R e q u e s t i ≤ A v a i l a b l e , that is ( 1 , 0 , 2 ) ≤ ( 3 , 3 , 2 ) which is true. We then pretend to allocate the requested resources leading to a new state as follows
  • 13. The obtained state is safe, hence we can immediately grant the newly requested resources to the process. However a further request of (3,3,0) by P4 cannot be granted, since the resources are not available. Safe State is determined by viewing all positive values in Available column. Process Allocation Max Available Need A B C A B C A B C A B C P0 0 1 0 7 5 3 2 3 0 7 4 3 P1 3 0 2 3 2 2 0 2 0 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1
  • 14. Deadlock Detection If a system does not provide deadlock avoidance or deadlock prevention, it must provide • An algorithm to examine the state of the system, deadlock detection. • An algorithm to recover from deadlock. Deadlock can be easily detected using the resource allocation graph. If a single instance of resources are present, deadlock can be detected by a presence of a cycle in the resource allocation graph. For a system with several instances of a resource type, this method is not sufficient. An algorithm is designed to detect deadlock in system with multiple instances of resources of a type. The algorithm is similar to Banker’s Algorithm. It uses several data structures such as Available, Allocation and Request.
  • 15. The working of algorithm is shown below. 1. Let Work and Finish be vectors of length m and n respectively. Work = Available. (initialization) if A llocation i ≠ 0 , F in ish [i] = false E lse, F in ish [i] = tru e 2. Find an index i such that Finish[i] == false Req u est i ≤ Work if no such I exists, go to step 4. 3 . Work = Work + A llocation i F in ish [i] = tru e Go to Step 2. 4. If F in ish [i] == false , then the system is in a deadlocked state.
  • 16. Deadlock Recovery When a detection algorithm detects a deadlock, deadlock is manually or automatically handled to recover the safe state of the system. There are two options of breaking a deadlock, abort one or more processes or to pre-empt some resources.
  • 17. Process Termination Abort all deadlocked processes: This method does break the deadlock but with a great expense. This method involves terminating all the processes involved in the deadlock state. Abort one process at a time until deadlock cycle is eliminated: This method is more efficient than terminating all the processes. A deadlock detection algorithm is implemented to determine which process to be terminated. Processes whose termination incurs minimum cost are terminated.
  • 18. Resource Pre-emption Successive pre-emption of resources to deal with deadlock. Three issues needs to be addressed in this method. 1. Selecting a victim: 2. Rollback: 3. Starvation: Selection of the resource to be pre-empted. Also involves determining the order of pre- emption to minimize the cost. Cost factor includes various parameters such as number of resources a deadlocked process holds or the mount of time the process has consumed so far. A process whose resource are pre-empted is rolled back up to a safe state from where it can restart its execution. Selecting victim based on cost parameters lead to starvation of the most expensive process as it is always picked as the victim. The solution to prevent starvation is to include number of roll backs for a process in the cost factor. A process must be chosen as victim accordingly.