SlideShare a Scribd company logo
6. Deadlock
11/22/2015 SDM SVV OS 1
Mr. S. V. Viraktamath
Dept of E&CE,
SDMCT, Dharwad
svvitc2011@gmail.com
Deadlock
Deadlock - System model, Deadlock
characterization, Methods for handling
deadlocks - Deadlock prevention, deadlock
avoidance, Deadlock detection and solution for
deadlock.
11/22/2015 SDM SVV OS 2
Diagram of process state.
11/22/2015 SDM SVV OS 3
Deadlock
• Multiprogramming ? – many processes –few
resources.
• States of processes –Ready-Run-Wait.
• Def:A set of blocked processes each holding a
resource and waiting to acquire a resource held
by another process in the set.
• Ex. When two trains approach each other.
• We describe methods that an operating system
can use to prevent or deal with deadlocks
11/22/2015 SDM SVV OS 4
The Deadlock Problem
• Example
– System has 2 disk drives.
– P1 and P2 each hold one disk drive and each needs
another one.
• Example
– semaphores A and B, initialized to 1
P0 P1
wait (A); wait(B)
wait (B); wait(A)
11/22/2015 SDM SVV OS 5
Bridge Crossing Example
• Traffic only in one direction.
• Each section of a bridge can be viewed as a resource.
• If a deadlock occurs, it can be resolved if one car backs
up (preempt resources and rollback).
• Several cars may have to be backed up if a deadlock
occurs.
• Starvation is possible.
11/22/2015 SDM SVV OS 6
Real time Deadlocks
11/22/2015 SDM SVV OS 7
Real time Deadlocks
11/22/2015 SDM SVV OS 8
Deadlock Condition
11/22/2015 SDM SVV OS 9
11/22/2015 SDM SVV OS 10
Deadlock in relationships is a part of boredom, stress and unmet expectations. For
example, Deadlock can occur in a situation when a girl1 is wanting for a guy2, who is
acquired by another girl2, and girl2 is wanting for a guy1 that is acquired by girl1. Since,
both girls are waiting for each other to release the guy, the condition is called deadlock.
Example
• You can't get a job without experience;
you can't get experience without a job.
• ºÀÄZÀÄÑ ©qÀ®Ý ªÀÄzsÀÄªÉ DUÀĪÀ¢®è; ªÀÄzsÀĪÉ
DUÀ®Ý ºÀÄZÀÄÑ ©qÉÆ¢®è
11/22/2015 SDM SVV OS 11
System Model
• 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
11/22/2015 SDM SVV OS 12
Deadlock Characterization
1. Mutual exclusion: only one process at a time
can use a resource.
2. Hold and wait: a process holding at least one
resource is waiting to acquire additional
resources held by other processes.
11/22/2015 SDM SVV OS 13
Deadlock can arise if four conditions hold simultaneously.
Deadlock Characterization
3. No preemption: a resource can be released
only voluntarily by the process holding it, after
that process has completed its task.
4. Circular wait: there exists a set {P0, P1, …,
Pn} of waiting processes such that P0 is
waiting for a resource that is held by P1, P1 is
waiting for a resource that is held by P2, …,
Pn–1 is waiting for a resource that is held by
Pn, and Pn is waiting for a resource that is held
by P0.
11/22/2015 SDM SVV OS 14
Deadlock can arise if four conditions hold simultaneously.
Deadlock Characterization
MHNC
11/22/2015 SDM SVV OS 15
Resource allocation graph
• Why u plot Freq Response?
• Cricket results why graphs/plots???
11/22/2015 SDM SVV OS 16
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 P1  Rj
• Assignment edge – directed edge Rj  Pi
11/22/2015 SDM SVV OS 17
A set of vertices V and a set of edges E.
Resource-Allocation Graph (Cont.)
• Process
• Resource Type with 4 instances
• Pi requests instance of Rj
• Pi is holding an instance of Rj
11/22/2015 SDM SVV OS 18
Pi
Pi
Example of a Resource Allocation Graph
11/22/2015 SDM SVV OS 19
P={P1,P2,P3}
R={R1,R2,R3,R4}
E={P1R1, P2R3,R1P1,R3P3,R2P1,R2P2}
Example of a Resource Allocation Graph
11/22/2015 SDM SVV OS 20
Instances R1=1, R2=2, R3=1, R4=3
Process states: P1 holding R2 and is waiting for an
instance of resource type R1, similarly P2, P3
Resource Allocation Graph With A Deadlock
11/22/2015 SDM SVV OS 21
Graph With A Cycle But No Deadlock
11/22/2015 SDM SVV OS 22
Is there any Deadlock?
Basic Facts
• If graph contains no cycles  no deadlock.
• If graph contains a cycle 
– if only one instance per resource type, then
deadlock.
– if several instances per resource type, possibility of
deadlock.
•
11/22/2015 SDM SVV OS 23
Summary
• Examples-deadlock
• Four conditions for deadlock
– M H N C
• Resource allocation graph?
• Cycle
– No cycle – 100% no deadlock
– Cycle
• Single instances – 100% Deadlock
• Many instances – Possibility of deadlock
11/22/2015 SDM SVV OS 24
Methods for Handling Deadlocks
• Ensure that the system will never enter a
deadlock state.
• 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.
•
11/22/2015 SDM SVV OS 25
Deadlock Prevention
• Four conditions for Deadlock
– Mutual exclusion
– Hold and wait
– No preemption
– Circular wait
• Prevent Deadlock Ensure that at least one
of these cannot hold (any one is false)
• Prevention is better than cure
11/22/2015 SDM SVV OS 26
Deadlock Prevention
• Mutual Exclusion –This condition must hold for
non-sharable resources. Ex. Printer. Read only
files No need to wait for access. To make this
false all resources should be sharable.
• Hold and Wait –Protocols, (No wait/ No Hold)
• Process must request all resources and be
allocated. (No wait)
• Must guarantee that whenever a process requests
a resource, it does not hold any other resources.
(No Hold)
11/22/2015 SDM SVV OS 27
Deadlock Prevention
• Ex. Copy data from Tape drive to disc, sorts
the disk file and then prints result to a printer.
• No wait: Request Tape drive, Disk file and
printer.
• No Hold: Request Tape drive and disk file,
Release resources, again request disk file and
printer.
• Dis: Protocol 1 Resource Utilization is less.
11/22/2015 SDM SVV OS 28
Deadlock Prevention
• 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.
11/22/2015 SDM SVV OS 29
Deadlock Prevention
• Circular Wait – impose a total ordering of all
resource types, and require that each process
requests resources in an increasing order of
enumeration.
11/22/2015 SDM SVV OS 30
– Ex Tape drive -1; Disk drive-5 and Printer -9 Each
process can request resources in increasing order.
– 1:The process can request instance of resource
type rj iff F(Rj)>F(Ri). (Ri –is holding resources)
– 2:Whenever Pi req for Rj, it has released any
resources Ri such that F(Ri)>=F(Rj).
11/22/2015 SDM SVV OS 31
F(tapedrive)=1
F(disk drive)=5
F(printer)=9
Deadlock Avoidance
• Deadlock prevention side effect– Low device
utilization and reduced system through put.
• Alternative Method—Require additional
information about how resources are to be
requested.
• Ex. P1 req R1 then R2 and P2 req R2 then R1
possible to avoid deadlock.
• Deadlock avoidance algorithm dynamically
examines resource allocation state to ensure
that there is no circular wait.
11/22/2015 SDM SVV OS 32
Deadlock Avoidance
• Safe State: A system is in safe state if there
exists a safe sequence.
• When a process requests an available resource,
system must decide if immediate allocation leaves
the system in a safe state. (Budget Plan/Bank)
11/22/2015 SDM SVV OS 33
• Safe sequence
– 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.
11/22/2015 SDM SVV OS 34
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.
11/22/2015 SDM SVV OS 35
Safe, Unsafe , Deadlock State
11/22/2015 SDM SVV OS 36
Safe sequence
• Ex.
• Is there any safe sequence?
• 3p15 P0 10 P2 12
11/22/2015 SDM SVV OS 37
Process Max.
Needs
Holding Current
Needs
Total Available
P0 10 5 5 12 3
P1 4 2 2
P2 9 2 2
Safe sequence
• Ex.
• Is there any safe sequence?
11/22/2015 SDM SVV OS 38
Process Max.
Needs
Holding Current
Needs
Total Available
P0 10 5 5 12 2
P1 4 2 2
P2 9 3 2
Avoidance algorithms
• Single instance of a resource type. Use a
resource-allocation graph
• Multiple instances of a resource type. Use the
banker’s algorithm (Not bakery Algorithm)
11/22/2015 SDM SVV OS 39
Resource-Allocation Graph Scheme
• Claim edge Pi  Rj indicated that process Pi 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.
• Resources must be claimed a priori in the system.
11/22/2015 SDM SVV OS 40
Resource-Allocation Graph
11/22/2015 SDM SVV OS 41
Unsafe State In Resource-Allocation Graph
11/22/2015 SDM SVV OS 42
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
•
11/22/2015 SDM SVV OS 43
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.
11/22/2015 SDM SVV OS 44
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].
11/22/2015 SDM SVV OS 45
Data Structures for the Banker’s Algorithm
• Ex.
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 . … …..
…
Need
A B C
P0 7 4 3
11/22/2015 SDM SVV OS 46
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.
11/22/2015 SDM SVV OS 47
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.
When a request for resources is made by process
Pi, the following actions are taken:
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.
11/22/2015 SDM SVV OS 48
3. Pretend to allocate requested resources to
Pi by modifying the state as follows:
Available = Available – Request;
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
11/22/2015 SDM SVV OS 49
Find the safe sequence
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? Need?
A B C A B C A B C
P0 0 1 0 7 5 3
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
11/22/2015 SDM SVV OS 50
3 3 2
Total 7 2 5
Example of Banker’s Algorithm
Allocation Max Available Need=max-Allocation?
A B C A B C A B C
P0 0 1 0 7 5 3
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
11/22/2015 SDM SVV OS 51
3 3 2
Total 7 2 5
• 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
• Is the system in a safe state?
• since the sequence < P1, P3, P4, P2, P0> satisfies safety
criteria.
11/22/2015 SDM SVV OS 52
Available is 3 3 2
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 1 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?
11/22/2015 SDM SVV OS 53
Is the system safe?
Deadlock Detection
• If a system does not employ either a deadlock-
prevention or a deadlock avoidance algorithm
– Then a deadlock situation may occur.
• In this environment, the system must provide:
– Detection algorithm
– Recovery scheme
• Two methods
– Single Instance of Each Resource Type
– Several Instances of a Resource Type
11/22/2015 SDM SVV OS 54
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.
11/22/2015 SDM SVV OS 55
Resource-Allocation Graph and Wait-for Graph
11/22/2015 SDM SVV OS 56
Resource-Allocation Graph Corresponding wait-for graph
Several Instances of a Resource Type
• Can we use wait for graph – Cycles-to detect
deadlock?
• The algorithm employs several time-varying
data structures that are similar to those used in
the banker's algorithm
• Can you recall those data structures now…
11/22/2015 SDM SVV OS 57
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 [ij] = k, then
process Pi is requesting k more instances of
resource type. Rj.
11/22/2015 SDM SVV OS 58
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.
11/22/2015 SDM SVV OS 59
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.
11/22/2015 SDM SVV OS 60
Algorithm requires an order of (m x n2)operations to detect
whether the system is in deadlocked state.
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
• Is the system in safe state?
11/22/2015 SDM SVV OS 61
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:
AllocationRequest 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.
11/22/2015 SDM SVV OS 62
Example of Detection Algorithm
Allocation Request Available (7 2 6)
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.
11/22/2015 SDM SVV OS 63
Process completion
P0- 0 1 0
P2-3 1 3
P3-5 2 4
P1-7 2 4
P4-7 2 6
• P2 requests an additional instance of type C.
Request
A B C available 0 0 0
P0 0 0 0
P1 2 0 1
P2 0 0 1
P3 1 0 0
P4 0 0 2
• Is the system in safe state?
11/22/2015 SDM SVV OS 64
• P2 requests an additional instance of type C.
Request
A B C
P0 0 0 0
P1 2 0 1
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.
11/22/2015 SDM SVV OS 65
P0- 0 1 0
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.
11/22/2015 SDM SVV OS 66
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?
– Priority of the process.
– How long process has computed, and how much longer to
completion.
– Resources the process has used.
– Resources process needs to complete.
– How many processes will need to be terminated.
– Is process interactive or batch?
11/22/2015 SDM SVV OS 67
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.
11/22/2015 SDM SVV OS 68
11/22/2015 SDM SVV OS 69
End of Topic Deadlock
11/22/2015 SDM SVV OS 70

More Related Content

What's hot

Deadlock
DeadlockDeadlock
Deadlock
VISHAL DONGA
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
IkhtiarUddinShaHin
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
Wayne Jones Jnr
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
EktaVaswani2
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
SRINIVASUNIVERSITYEN
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
ushabarad142
 
Deadlock
DeadlockDeadlock
Bankers
BankersBankers
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
Nivedita Kasturi
 
Deadlock
DeadlockDeadlock
Deadlock
Mohd Arif
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
Karam Munir Butt
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
lalithambiga kamaraj
 
OSCh8
OSCh8OSCh8
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
C.U
 
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
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
A. S. M. Shafi
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
Shijin Raj P
 
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
Rai University
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
Matthew Chang
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
totallooser
 

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 and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Deadlock
DeadlockDeadlock
Deadlock
 
Bankers
BankersBankers
Bankers
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
OSCh8
OSCh8OSCh8
OSCh8
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
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)
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
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
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
 

Viewers also liked

Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
Sweetestangel Kochar
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
Ornithopter project
Ornithopter projectOrnithopter project
Ornithopter project
Korchipatis Physics
 
Banker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy PitchBanker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy Pitch
Debashish Banerjee
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnism
Vijay Patil
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism report
Vijay Patil
 
Introduction to Operating system
Introduction to Operating systemIntroduction to Operating system
Introduction to Operating system
Muhammad Aqeel
 
A petri-net
A petri-netA petri-net
A petri-net
Omar Al-Sabek
 
Lecture5
Lecture5Lecture5
Lecture5
jntu
 
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
Monica Sabharwal
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
InteX Research Lab
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
vinay arora
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 
Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlocks
lionpeal
 
Holography
HolographyHolography
Holography
mandeep kaur virk
 
Dead Lock
Dead LockDead Lock
Dead Lock
Ramasubbu .P
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
Sonali Chauhan
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
Amir Payberah
 

Viewers also liked (18)

Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Ornithopter project
Ornithopter projectOrnithopter project
Ornithopter project
 
Banker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy PitchBanker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy Pitch
 
Ornithopter flying wing mecahnism
Ornithopter flying wing mecahnismOrnithopter flying wing mecahnism
Ornithopter flying wing mecahnism
 
Ornithopter flying wing mecahnism report
Ornithopter flying wing mecahnism reportOrnithopter flying wing mecahnism report
Ornithopter flying wing mecahnism report
 
Introduction to Operating system
Introduction to Operating systemIntroduction to Operating system
Introduction to Operating system
 
A petri-net
A petri-netA petri-net
A petri-net
 
Lecture5
Lecture5Lecture5
Lecture5
 
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
2009 Punjab Technical University B.C.A OPERATING SYSTEM Question paper
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Intro to Deadlocks
Intro to DeadlocksIntro to Deadlocks
Intro to Deadlocks
 
Holography
HolographyHolography
Holography
 
Dead Lock
Dead LockDead Lock
Dead Lock
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 

Similar to Deadlock_SVVSDM_DWD

Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
DenisPriscus
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
AUST
 
Deadlock
DeadlockDeadlock
Deadlock
Rajapriya82
 
Deadlock
DeadlockDeadlock
Deadlock
Rajapriya82
 
Deadlock Backgroud.pptx
Deadlock Backgroud.pptxDeadlock Backgroud.pptx
Deadlock Backgroud.pptx
infomerlin
 
Lecture # 10-11 for deadlock operating system.ppt
Lecture # 10-11 for deadlock operating system.pptLecture # 10-11 for deadlock operating system.ppt
Lecture # 10-11 for deadlock operating system.ppt
RiaanSadiq
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
shreesha16
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
Nazir Ahmed
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
KokilaK25
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
Nusaike Mufthie
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
Harika Pudugosula
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
hetrathod001
 
An brief introduction to Deadlocks in OS
An brief introduction to Deadlocks in OSAn brief introduction to Deadlocks in OS
An brief introduction to Deadlocks in OS
RaviKiranVarma4
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
shrijanasharma3
 
10. deadlock
10. deadlock10. deadlock
10. deadlock
Robbie AkaChopa
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
Dwight Sabio
 
Deadlocks
DeadlocksDeadlocks
deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
Monirul Islam
 
24 to 25 deadlockprevention
24 to 25 deadlockprevention24 to 25 deadlockprevention
24 to 25 deadlockprevention
myrajendra
 
OS deadlock.pptx
OS deadlock.pptxOS deadlock.pptx
OS deadlock.pptx
rpbbhalerao2000
 

Similar to Deadlock_SVVSDM_DWD (20)

Chapter5_Deadlock.pptx
Chapter5_Deadlock.pptxChapter5_Deadlock.pptx
Chapter5_Deadlock.pptx
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock Backgroud.pptx
Deadlock Backgroud.pptxDeadlock Backgroud.pptx
Deadlock Backgroud.pptx
 
Lecture # 10-11 for deadlock operating system.ppt
Lecture # 10-11 for deadlock operating system.pptLecture # 10-11 for deadlock operating system.ppt
Lecture # 10-11 for deadlock operating system.ppt
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
An brief introduction to Deadlocks in OS
An brief introduction to Deadlocks in OSAn brief introduction to Deadlocks in OS
An brief introduction to Deadlocks in OS
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
10. deadlock
10. deadlock10. deadlock
10. deadlock
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
 
24 to 25 deadlockprevention
24 to 25 deadlockprevention24 to 25 deadlockprevention
24 to 25 deadlockprevention
 
OS deadlock.pptx
OS deadlock.pptxOS deadlock.pptx
OS deadlock.pptx
 

Recently uploaded

Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
ydzowc
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
riddhimaagrawal986
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Sinan KOZAK
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 

Recently uploaded (20)

Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
原版制作(Humboldt毕业证书)柏林大学毕业证学位证一模一样
 
People as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimalaPeople as resource Grade IX.pdf minimala
People as resource Grade IX.pdf minimala
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
Optimizing Gradle Builds - Gradle DPE Tour Berlin 2024
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 

Deadlock_SVVSDM_DWD

  • 1. 6. Deadlock 11/22/2015 SDM SVV OS 1 Mr. S. V. Viraktamath Dept of E&CE, SDMCT, Dharwad svvitc2011@gmail.com
  • 2. Deadlock Deadlock - System model, Deadlock characterization, Methods for handling deadlocks - Deadlock prevention, deadlock avoidance, Deadlock detection and solution for deadlock. 11/22/2015 SDM SVV OS 2
  • 3. Diagram of process state. 11/22/2015 SDM SVV OS 3
  • 4. Deadlock • Multiprogramming ? – many processes –few resources. • States of processes –Ready-Run-Wait. • Def:A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. • Ex. When two trains approach each other. • We describe methods that an operating system can use to prevent or deal with deadlocks 11/22/2015 SDM SVV OS 4
  • 5. The Deadlock Problem • Example – System has 2 disk drives. – P1 and P2 each hold one disk drive and each needs another one. • Example – semaphores A and B, initialized to 1 P0 P1 wait (A); wait(B) wait (B); wait(A) 11/22/2015 SDM SVV OS 5
  • 6. Bridge Crossing Example • Traffic only in one direction. • Each section of a bridge can be viewed as a resource. • If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). • Several cars may have to be backed up if a deadlock occurs. • Starvation is possible. 11/22/2015 SDM SVV OS 6
  • 10. 11/22/2015 SDM SVV OS 10 Deadlock in relationships is a part of boredom, stress and unmet expectations. For example, Deadlock can occur in a situation when a girl1 is wanting for a guy2, who is acquired by another girl2, and girl2 is wanting for a guy1 that is acquired by girl1. Since, both girls are waiting for each other to release the guy, the condition is called deadlock.
  • 11. Example • You can't get a job without experience; you can't get experience without a job. • ºÀÄZÀÄÑ ©qÀ®Ý ªÀÄzsÀÄªÉ DUÀĪÀ¢®è; ªÀÄzsÀÄªÉ DUÀ®Ý ºÀÄZÀÄÑ ©qÉÆ¢®è 11/22/2015 SDM SVV OS 11
  • 12. System Model • 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 11/22/2015 SDM SVV OS 12
  • 13. Deadlock Characterization 1. Mutual exclusion: only one process at a time can use a resource. 2. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. 11/22/2015 SDM SVV OS 13 Deadlock can arise if four conditions hold simultaneously.
  • 14. Deadlock Characterization 3. No preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. 4. Circular wait: there exists a set {P0, P1, …, Pn} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0. 11/22/2015 SDM SVV OS 14 Deadlock can arise if four conditions hold simultaneously.
  • 16. Resource allocation graph • Why u plot Freq Response? • Cricket results why graphs/plots??? 11/22/2015 SDM SVV OS 16
  • 17. 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 P1  Rj • Assignment edge – directed edge Rj  Pi 11/22/2015 SDM SVV OS 17 A set of vertices V and a set of edges E.
  • 18. Resource-Allocation Graph (Cont.) • Process • Resource Type with 4 instances • Pi requests instance of Rj • Pi is holding an instance of Rj 11/22/2015 SDM SVV OS 18 Pi Pi
  • 19. Example of a Resource Allocation Graph 11/22/2015 SDM SVV OS 19 P={P1,P2,P3} R={R1,R2,R3,R4} E={P1R1, P2R3,R1P1,R3P3,R2P1,R2P2}
  • 20. Example of a Resource Allocation Graph 11/22/2015 SDM SVV OS 20 Instances R1=1, R2=2, R3=1, R4=3 Process states: P1 holding R2 and is waiting for an instance of resource type R1, similarly P2, P3
  • 21. Resource Allocation Graph With A Deadlock 11/22/2015 SDM SVV OS 21
  • 22. Graph With A Cycle But No Deadlock 11/22/2015 SDM SVV OS 22 Is there any Deadlock?
  • 23. 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. • 11/22/2015 SDM SVV OS 23
  • 24. Summary • Examples-deadlock • Four conditions for deadlock – M H N C • Resource allocation graph? • Cycle – No cycle – 100% no deadlock – Cycle • Single instances – 100% Deadlock • Many instances – Possibility of deadlock 11/22/2015 SDM SVV OS 24
  • 25. Methods for Handling Deadlocks • Ensure that the system will never enter a deadlock state. • 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. • 11/22/2015 SDM SVV OS 25
  • 26. Deadlock Prevention • Four conditions for Deadlock – Mutual exclusion – Hold and wait – No preemption – Circular wait • Prevent Deadlock Ensure that at least one of these cannot hold (any one is false) • Prevention is better than cure 11/22/2015 SDM SVV OS 26
  • 27. Deadlock Prevention • Mutual Exclusion –This condition must hold for non-sharable resources. Ex. Printer. Read only files No need to wait for access. To make this false all resources should be sharable. • Hold and Wait –Protocols, (No wait/ No Hold) • Process must request all resources and be allocated. (No wait) • Must guarantee that whenever a process requests a resource, it does not hold any other resources. (No Hold) 11/22/2015 SDM SVV OS 27
  • 28. Deadlock Prevention • Ex. Copy data from Tape drive to disc, sorts the disk file and then prints result to a printer. • No wait: Request Tape drive, Disk file and printer. • No Hold: Request Tape drive and disk file, Release resources, again request disk file and printer. • Dis: Protocol 1 Resource Utilization is less. 11/22/2015 SDM SVV OS 28
  • 29. Deadlock Prevention • 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. 11/22/2015 SDM SVV OS 29
  • 30. Deadlock Prevention • Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. 11/22/2015 SDM SVV OS 30
  • 31. – Ex Tape drive -1; Disk drive-5 and Printer -9 Each process can request resources in increasing order. – 1:The process can request instance of resource type rj iff F(Rj)>F(Ri). (Ri –is holding resources) – 2:Whenever Pi req for Rj, it has released any resources Ri such that F(Ri)>=F(Rj). 11/22/2015 SDM SVV OS 31 F(tapedrive)=1 F(disk drive)=5 F(printer)=9
  • 32. Deadlock Avoidance • Deadlock prevention side effect– Low device utilization and reduced system through put. • Alternative Method—Require additional information about how resources are to be requested. • Ex. P1 req R1 then R2 and P2 req R2 then R1 possible to avoid deadlock. • Deadlock avoidance algorithm dynamically examines resource allocation state to ensure that there is no circular wait. 11/22/2015 SDM SVV OS 32
  • 33. Deadlock Avoidance • Safe State: A system is in safe state if there exists a safe sequence. • When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. (Budget Plan/Bank) 11/22/2015 SDM SVV OS 33
  • 34. • Safe sequence – 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. 11/22/2015 SDM SVV OS 34
  • 35. 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. 11/22/2015 SDM SVV OS 35
  • 36. Safe, Unsafe , Deadlock State 11/22/2015 SDM SVV OS 36
  • 37. Safe sequence • Ex. • Is there any safe sequence? • 3p15 P0 10 P2 12 11/22/2015 SDM SVV OS 37 Process Max. Needs Holding Current Needs Total Available P0 10 5 5 12 3 P1 4 2 2 P2 9 2 2
  • 38. Safe sequence • Ex. • Is there any safe sequence? 11/22/2015 SDM SVV OS 38 Process Max. Needs Holding Current Needs Total Available P0 10 5 5 12 2 P1 4 2 2 P2 9 3 2
  • 39. Avoidance algorithms • Single instance of a resource type. Use a resource-allocation graph • Multiple instances of a resource type. Use the banker’s algorithm (Not bakery Algorithm) 11/22/2015 SDM SVV OS 39
  • 40. Resource-Allocation Graph Scheme • Claim edge Pi  Rj indicated that process Pi 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. • Resources must be claimed a priori in the system. 11/22/2015 SDM SVV OS 40
  • 42. Unsafe State In Resource-Allocation Graph 11/22/2015 SDM SVV OS 42
  • 43. 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 • 11/22/2015 SDM SVV OS 43
  • 44. 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. 11/22/2015 SDM SVV OS 44
  • 45. 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]. 11/22/2015 SDM SVV OS 45 Data Structures for the Banker’s Algorithm
  • 46. • Ex. 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 . … ….. … Need A B C P0 7 4 3 11/22/2015 SDM SVV OS 46
  • 47. 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. 11/22/2015 SDM SVV OS 47
  • 48. 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. When a request for resources is made by process Pi, the following actions are taken: 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. 11/22/2015 SDM SVV OS 48
  • 49. 3. Pretend to allocate requested resources to Pi by modifying the state as follows: Available = Available – Request; 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 11/22/2015 SDM SVV OS 49 Find the safe sequence
  • 50. 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? Need? A B C A B C A B C P0 0 1 0 7 5 3 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 11/22/2015 SDM SVV OS 50 3 3 2 Total 7 2 5
  • 51. Example of Banker’s Algorithm Allocation Max Available Need=max-Allocation? A B C A B C A B C P0 0 1 0 7 5 3 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 11/22/2015 SDM SVV OS 51 3 3 2 Total 7 2 5
  • 52. • 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 • Is the system in a safe state? • since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria. 11/22/2015 SDM SVV OS 52 Available is 3 3 2
  • 53. 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 1 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? 11/22/2015 SDM SVV OS 53 Is the system safe?
  • 54. Deadlock Detection • If a system does not employ either a deadlock- prevention or a deadlock avoidance algorithm – Then a deadlock situation may occur. • In this environment, the system must provide: – Detection algorithm – Recovery scheme • Two methods – Single Instance of Each Resource Type – Several Instances of a Resource Type 11/22/2015 SDM SVV OS 54
  • 55. 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. 11/22/2015 SDM SVV OS 55
  • 56. Resource-Allocation Graph and Wait-for Graph 11/22/2015 SDM SVV OS 56 Resource-Allocation Graph Corresponding wait-for graph
  • 57. Several Instances of a Resource Type • Can we use wait for graph – Cycles-to detect deadlock? • The algorithm employs several time-varying data structures that are similar to those used in the banker's algorithm • Can you recall those data structures now… 11/22/2015 SDM SVV OS 57
  • 58. 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 [ij] = k, then process Pi is requesting k more instances of resource type. Rj. 11/22/2015 SDM SVV OS 58
  • 59. 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. 11/22/2015 SDM SVV OS 59
  • 60. 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. 11/22/2015 SDM SVV OS 60 Algorithm requires an order of (m x n2)operations to detect whether the system is in deadlocked state.
  • 61. 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 • Is the system in safe state? 11/22/2015 SDM SVV OS 61
  • 62. 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: AllocationRequest 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. 11/22/2015 SDM SVV OS 62
  • 63. Example of Detection Algorithm Allocation Request Available (7 2 6) 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. 11/22/2015 SDM SVV OS 63 Process completion P0- 0 1 0 P2-3 1 3 P3-5 2 4 P1-7 2 4 P4-7 2 6
  • 64. • P2 requests an additional instance of type C. Request A B C available 0 0 0 P0 0 0 0 P1 2 0 1 P2 0 0 1 P3 1 0 0 P4 0 0 2 • Is the system in safe state? 11/22/2015 SDM SVV OS 64
  • 65. • P2 requests an additional instance of type C. Request A B C P0 0 0 0 P1 2 0 1 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. 11/22/2015 SDM SVV OS 65 P0- 0 1 0
  • 66. 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. 11/22/2015 SDM SVV OS 66
  • 67. 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? – Priority of the process. – How long process has computed, and how much longer to completion. – Resources the process has used. – Resources process needs to complete. – How many processes will need to be terminated. – Is process interactive or batch? 11/22/2015 SDM SVV OS 67
  • 68. 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. 11/22/2015 SDM SVV OS 68
  • 70. End of Topic Deadlock 11/22/2015 SDM SVV OS 70