SlideShare ist ein Scribd-Unternehmen logo
1 von 43
UNIT 3: DEADLOCKUNIT 3: DEADLOCK
MCA IIMCA II
Chapter 7: DeadlocksChapter 7: Deadlocks
7.1 System Model
7.2 Deadlock Characterization
7.3 Methods for Handling Deadlocks
7.4 Deadlock Prevention
7.5 Deadlock Avoidance
7.6 Deadlock Detection
7.7 Recovery from Deadlock
Chapter ObjectivesChapter Objectives
To develop a description of deadlocks, which prevent
sets of concurrent processes from completing their tasks
To present a number of different methods for preventing,
avoiding, or detecting deadlocks in a computer system
7.1 System Model7.1 System Model
The Deadlock ProblemThe Deadlock Problem
A deadlock consists of a set of blocked processes, each
holding a resource and waiting to acquire a resource held by
another process in the set
Example #1
A system has 2 disk drives
P1 and P2 each hold one disk drive and each needs the other one
Example #2
Semaphores A and B, initialized to 1
P0 P1
wait (A); wait(B)
wait (B); wait(A)
Bridge Crossing ExampleBridge Crossing Example
Traffic only in one direction
The resource is a one-lane bridge
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
System ModelSystem Model
Resource types R1, R2, . . ., Rm
CPU cycles, memory space, I/O devices
Each resource type Ri has 1 or moreinstances
Each process utilizes a resource as follows:
request
use
release
7.2 Deadlock Characterization7.2 Deadlock Characterization
Deadlock CharacterizationDeadlock Characterization
Mutual exclusion: only one process at a time can use a
resource
Hold and wait: a process holding at least one resource is
waiting to acquire additional resources held by other
processes
No preemption: a resource can be released only
voluntarily by the process holding it after that process has
completed its task
Circular wait: there exists a set {P0, P1, …, P0} of waiting
processes such that P0 is waiting for a resource that is held
by P1, P1 is waiting for a resource that is held by
P2, …, Pn–1 is waiting for a resource that is held by
Pn, and Pn is waiting for a resource that is held by P0
Deadlock can arise if four conditions hold simultaneously.
Resource-Allocation GraphResource-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
A set of vertices V and a set of edges E.
Resource-Allocation Graph (Cont.)Resource-Allocation Graph (Cont.)
Process
Resource Type with 4 instances
Pi requests instance of Rj
Pi is holding an instance of Rj
Pi
Pi
Rj
Rj
Resource Allocation Graph With A DeadlockResource Allocation Graph With A Deadlock
Before P3 requested an
instance of R2
After P3 requested an
instance of R2
Graph With A Cycle But No DeadlockGraph With A Cycle But No Deadlock
Process P4 may release its instance of resource type R2. That
resource can then be allocated to P3, thereby breaking the cycle.
Relationship of cycles to deadlocksRelationship of cycles to deadlocks
If a resource allocation graph contains no cycles ⇒ no deadlock
If a resource allocation graph contains a cycle and if only one instance exists per
resource type ⇒ deadlock
If a resource allocation graph contains a cycle and and if several instances
exists per resource type ⇒ possibility of deadlock
7.3 Methods for Handling7.3 Methods for Handling
DeadlocksDeadlocks
Methods for Handling DeadlocksMethods for Handling Deadlocks
Prevention
Ensure that the system will never enter a deadlock state
Avoidance
Ensure that the system will never enter an unsafe state
Detection
Allow the system to enter a deadlock state and then recover
Do Nothing
Ignore the problem and let the user or system administrator respond to the problem;
used by most operating systems, including Windows and UNIX
7.4 Deadlock Prevention7.4 Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Mutual Exclusion – The mutual-exclusion condition must
hold for non-sharable resources
Hold and Wait – we must guarantee that whenever a
process requests a resource, it does not hold any other
resources
Require a process to request and be allocated all its resources
before it begins execution, or allow a process to request
resources only when the process has none
Result: Low resource utilization; starvation possible
To prevent deadlock, we can restrain the ways that a request can be made
Deadlock Prevention (Cont.)Deadlock Prevention (Cont.)
No Preemption –
If a process that is holding some resources requests another
resource that cannot be immediately allocated to it, then all
resources currently being held are released
Preempted resources are added to the list of resources for which
the process is waiting
A process will be restarted only when it can regain its old
resources, as well as the new ones that it is requesting
Circular Wait – impose a total ordering of all resource types, and
require that each process requests resources in an increasing order
of enumeration. For example:
F(tape drive) = 1
F(disk drive) = 5
F(printer) = 12
7.5 Deadlock Avoidance7.5 Deadlock Avoidance
Deadlock AvoidanceDeadlock Avoidance
Simplest and most useful model requires that each process declare
the maximum number of resources of each type that it may need
The deadlock-avoidance algorithm dynamically examines the
resource-allocation state to ensure that there can never be a
circular-wait condition
A resource-allocation state is defined by the number of available
and allocated resources, and the maximum demands of the
processes
Requires that the system has some additional a priori information
available.
a priori: formed or conceived beforehand
Safe StateSafe State
When a process requests an available resource, the system must
decide if immediate allocation leaves the system in a safe state
A system is in a safe state only if there exists a safe sequence
A sequence of processes <P1, P2, …, Pn> is a safe sequence for
the current allocation state if, for each Pi, the resource requests
that Pi can still make, can be satisfied by currently available
resources plus resources held by all Pj, with j < i.
That is:
If the 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
Safe State (continued)Safe State (continued)
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
Safe, Unsafe , Deadlock StateSafe, Unsafe , Deadlock State
Avoidance algorithmsAvoidance algorithms
For a single instance of a resource type, use a resource-
allocation graph
For multiple instances of a resource type, use the banker’s
algorithm
Resource-Allocation Graph SchemeResource-Allocation Graph Scheme
Introduce a new kind of edge called a claim edge
Claim edge Pi Rj indicates that process Pj may
request resource Rj; which is represented by a dashed line
A claim edge converts to a request edge when a process
requests a resource
A request edge converts to an assignment edge when the
resource is allocated to the process
When a resource is released by a process, an assignment
edge reconverts to a claim edge
Resources must be claimed a priori in the system
Resource-Allocation Graph withResource-Allocation Graph with
Claim EdgesClaim Edges
Request
edge
Assignment
edge
Claim
edge
Claim
edge
Unsafe State In Resource-Allocation GraphUnsafe State In Resource-Allocation Graph
Assignment
edge
Request
edge
Assignment
edgeClaim
edge
Resource-Allocation Graph AlgorithmResource-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
Banker’s AlgorithmBanker’s Algorithm
Used when there exists multiple instances of a resource type
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
Data Structures for the Banker’sData Structures for the Banker’s
AlgorithmAlgorithm
Available: Vector of length m. If available [j] = k, there are k
instances of resource type Rj available.
Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most
k instances of resource type Rj.
Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently
allocated k instances of Rj.
Need: n x m matrix. If Need[i,j] = k, then Pi may need k more
instances of Rj to complete its task.
Need [i,j] = Max[i,j] – Allocation [i,j]
Let n = number of processes, and m = number of resources types.
7.6 Deadlock Detection7.6 Deadlock Detection
Deadlock DetectionDeadlock Detection
For deadlock detection, the system must provide
An algorithm that examines the state of the system to detect whether a
deadlock has occurred
And an algorithm to recover from the deadlock
A detection-and-recovery scheme requires various kinds of overhead
Run-time costs of maintaining necessary information and executing the
detection algorithm
Potential losses inherent in recovering from a deadlock
Single Instance of Each ResourceSingle Instance of Each Resource
TypeType
Requires the creation and maintenance of a wait-for graph
Consists of a variant of the resource-allocation graph
The graph is obtained by removing the resource nodes from
a resource-allocation graph and collapsing the appropriate
edges
Consequently; all 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
Resource-Allocation Graph and Wait-forResource-Allocation Graph and Wait-for
GraphGraph
Resource-Allocation Graph Corresponding wait-for graph
Multiple Instances of a ResourceMultiple Instances of a Resource
TypeType
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.
Required data structures:
Detection-Algorithm UsageDetection-Algorithm Usage
When, and how often, to invoke the detection algorithm depends on:
How often is a deadlock likely to occur?
How many processes will be affected by deadlock when it happens?
If the detection algorithm is invoked arbitrarily, there may be many
cycles in the resource graph and so we would not be able to tell which
one of the many deadlocked processes “caused” the deadlock
If the detection algorithm is invoked for every resource request, such an
action will incur a considerable overhead in computation time
A less expensive alternative is to invoke the algorithm when CPU
utilization drops below 40%, for example
This is based on the observation that a deadlock eventually cripples system
throughput and causes CPU utilization to drop
7.7 Recovery From Deadlock7.7 Recovery From Deadlock
Recovery from DeadlockRecovery from Deadlock
Two Approaches
Process termination
Resource preemption
Recovery from Deadlock:Recovery from Deadlock: Process TerminationProcess Termination
Abort all deadlocked processes
This approach will break the deadlock, but at great expense
Abort one process at a time until the deadlock cycle is
eliminated
This approach incurs considerable overhead, since, after each process is
aborted, a deadlock-detection algorithm must be re-invoked to determine
whether any processes are still deadlocked
Many factors may affect which process is chosen for
termination
What is the priority of the process?
How long has the process run so far and how much longer will the process
need to run before completing its task?
How many and what type of resources has the process used?
How many more resources does the process need in order to finish its task?
How many processes will need to be terminated?
Is the process interactive or batch?
Recovery from Deadlock:Recovery from Deadlock: ResourceResource
PreemptionPreemption
With this approach, we successively preempt some resources from
processes and give these resources to other processes until the
deadlock cycle is broken
When preemption is required to deal with deadlocks, then three
issues need to be addressed:
Selecting a victim – Which resources and which processes are to be
preempted?
Rollback – If we preempt a resource from a process, what should be
done with that process?
Starvation – How do we ensure that starvation will not occur? That is,
how can we guarantee that resources will not always be preempted
from the same process?
SummarySummary
Four necessary conditions must hold in the system for a deadlock
to occur
Mutual exclusion
Hold and wait
No preemption
Circular wait
Four principal methods for dealing with deadlocks
Use some protocol to (1) prevent or (2) avoid deadlocks, ensuring
that the system will never enter a deadlock state
Allow the system to enter a deadlock state, (3) detect it, and then
recover
 Recover by process termination or resource preemption
(4) Do nothing; ignore the problem altogether and pretend that
deadlocks never occur in the system (used by Windows and Unix)
To prevent deadlocks, we can ensure that at least one of the four
necessary conditions never holds
REFRENCESREFRENCES
Operating System Concepts – 9th
Edition By Silberchatz, Galvin and
Gagne

Weitere ähnliche Inhalte

Was ist angesagt?

Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lockKaram Munir Butt
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock GalvinSonali Chauhan
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & preventionIkhtiarUddinShaHin
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemAUST
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingTamannaSharma70
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemSara Ali
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating SystemRajan Shah
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYअनिकेत चौधरी
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocksA. S. M. Shafi
 

Was ist angesagt? (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Operating system - Deadlock
Operating system - DeadlockOperating system - Deadlock
Operating system - Deadlock
 
Deadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networkingDeadlock avoidance and prevention .. computer networking
Deadlock avoidance and prevention .. computer networking
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Ch8
Ch8Ch8
Ch8
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 

Andere mochten auch

Banker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy PitchBanker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy PitchDebashish Banerjee
 
Introduction to Operating system
Introduction to Operating systemIntroduction to Operating system
Introduction to Operating systemMuhammad Aqeel
 
Lecture5
Lecture5Lecture5
Lecture5jntu
 
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 paperMonica Sabharwal
 
Extreme semaphore 12 pax id290
Extreme semaphore 12 pax id290Extreme semaphore 12 pax id290
Extreme semaphore 12 pax id290STRiVER P.M.C.
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitorssgpraju
 

Andere mochten auch (14)

Banker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy PitchBanker's note - Blackstone Synergy Pitch
Banker's note - Blackstone Synergy Pitch
 
Bankers
BankersBankers
Bankers
 
Introduction to Operating system
Introduction to Operating systemIntroduction to Operating system
Introduction to Operating system
 
Deadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWDDeadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWD
 
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
 
Holography
HolographyHolography
Holography
 
Extreme semaphore 12 pax id290
Extreme semaphore 12 pax id290Extreme semaphore 12 pax id290
Extreme semaphore 12 pax id290
 
Handling data 1
Handling data 1Handling data 1
Handling data 1
 
Os Question Bank
Os Question BankOs Question Bank
Os Question Bank
 
Semaphores
SemaphoresSemaphores
Semaphores
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 

Ähnlich wie Mca ii os u-3 dead lock & io systems

Ähnlich wie Mca ii os u-3 dead lock & io systems (20)

Operating System
Operating SystemOperating System
Operating System
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
Ice
IceIce
Ice
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Chapter 5(five).pdf
Chapter 5(five).pdfChapter 5(five).pdf
Chapter 5(five).pdf
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
7.Dead Locks
7.Dead Locks7.Dead Locks
7.Dead Locks
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
 
Deadlock
DeadlockDeadlock
Deadlock
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Deadlock
DeadlockDeadlock
Deadlock
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 

Mehr von Rai University

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University Rai University
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,Rai University
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02Rai University
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditureRai University
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public financeRai University
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introductionRai University
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflationRai University
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economicsRai University
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructureRai University
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competitionRai University
 

Mehr von Rai University (20)

Brochure Rai University
Brochure Rai University Brochure Rai University
Brochure Rai University
 
Mm unit 4point2
Mm unit 4point2Mm unit 4point2
Mm unit 4point2
 
Mm unit 4point1
Mm unit 4point1Mm unit 4point1
Mm unit 4point1
 
Mm unit 4point3
Mm unit 4point3Mm unit 4point3
Mm unit 4point3
 
Mm unit 3point2
Mm unit 3point2Mm unit 3point2
Mm unit 3point2
 
Mm unit 3point1
Mm unit 3point1Mm unit 3point1
Mm unit 3point1
 
Mm unit 2point2
Mm unit 2point2Mm unit 2point2
Mm unit 2point2
 
Mm unit 2 point 1
Mm unit 2 point 1Mm unit 2 point 1
Mm unit 2 point 1
 
Mm unit 1point3
Mm unit 1point3Mm unit 1point3
Mm unit 1point3
 
Mm unit 1point2
Mm unit 1point2Mm unit 1point2
Mm unit 1point2
 
Mm unit 1point1
Mm unit 1point1Mm unit 1point1
Mm unit 1point1
 
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,Bdft ii, tmt, unit-iii,  dyeing & types of dyeing,
Bdft ii, tmt, unit-iii, dyeing & types of dyeing,
 
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02Bsc agri  2 pae  u-4.4 publicrevenue-presentation-130208082149-phpapp02
Bsc agri 2 pae u-4.4 publicrevenue-presentation-130208082149-phpapp02
 
Bsc agri 2 pae u-4.3 public expenditure
Bsc agri  2 pae  u-4.3 public expenditureBsc agri  2 pae  u-4.3 public expenditure
Bsc agri 2 pae u-4.3 public expenditure
 
Bsc agri 2 pae u-4.2 public finance
Bsc agri  2 pae  u-4.2 public financeBsc agri  2 pae  u-4.2 public finance
Bsc agri 2 pae u-4.2 public finance
 
Bsc agri 2 pae u-4.1 introduction
Bsc agri  2 pae  u-4.1 introductionBsc agri  2 pae  u-4.1 introduction
Bsc agri 2 pae u-4.1 introduction
 
Bsc agri 2 pae u-3.3 inflation
Bsc agri  2 pae  u-3.3  inflationBsc agri  2 pae  u-3.3  inflation
Bsc agri 2 pae u-3.3 inflation
 
Bsc agri 2 pae u-3.2 introduction to macro economics
Bsc agri  2 pae  u-3.2 introduction to macro economicsBsc agri  2 pae  u-3.2 introduction to macro economics
Bsc agri 2 pae u-3.2 introduction to macro economics
 
Bsc agri 2 pae u-3.1 marketstructure
Bsc agri  2 pae  u-3.1 marketstructureBsc agri  2 pae  u-3.1 marketstructure
Bsc agri 2 pae u-3.1 marketstructure
 
Bsc agri 2 pae u-3 perfect-competition
Bsc agri  2 pae  u-3 perfect-competitionBsc agri  2 pae  u-3 perfect-competition
Bsc agri 2 pae u-3 perfect-competition
 

Kürzlich hochgeladen

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 

Kürzlich hochgeladen (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 

Mca ii os u-3 dead lock & io systems

  • 1. UNIT 3: DEADLOCKUNIT 3: DEADLOCK MCA IIMCA II
  • 2. Chapter 7: DeadlocksChapter 7: Deadlocks 7.1 System Model 7.2 Deadlock Characterization 7.3 Methods for Handling Deadlocks 7.4 Deadlock Prevention 7.5 Deadlock Avoidance 7.6 Deadlock Detection 7.7 Recovery from Deadlock
  • 3. Chapter ObjectivesChapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present a number of different methods for preventing, avoiding, or detecting deadlocks in a computer system
  • 4. 7.1 System Model7.1 System Model
  • 5. The Deadlock ProblemThe Deadlock Problem A deadlock consists of a set of blocked processes, each holding a resource and waiting to acquire a resource held by another process in the set Example #1 A system has 2 disk drives P1 and P2 each hold one disk drive and each needs the other one Example #2 Semaphores A and B, initialized to 1 P0 P1 wait (A); wait(B) wait (B); wait(A)
  • 6. Bridge Crossing ExampleBridge Crossing Example Traffic only in one direction The resource is a one-lane bridge 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
  • 7. System ModelSystem Model Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices Each resource type Ri has 1 or moreinstances Each process utilizes a resource as follows: request use release
  • 8. 7.2 Deadlock Characterization7.2 Deadlock Characterization
  • 9. Deadlock CharacterizationDeadlock Characterization Mutual exclusion: only one process at a time can use a resource Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes No preemption: a resource can be released only voluntarily by the process holding it after that process has completed its task Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0 Deadlock can arise if four conditions hold simultaneously.
  • 10. Resource-Allocation GraphResource-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 A set of vertices V and a set of edges E.
  • 11. Resource-Allocation Graph (Cont.)Resource-Allocation Graph (Cont.) Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi Pi Rj Rj
  • 12. Resource Allocation Graph With A DeadlockResource Allocation Graph With A Deadlock Before P3 requested an instance of R2 After P3 requested an instance of R2
  • 13. Graph With A Cycle But No DeadlockGraph With A Cycle But No Deadlock Process P4 may release its instance of resource type R2. That resource can then be allocated to P3, thereby breaking the cycle.
  • 14. Relationship of cycles to deadlocksRelationship of cycles to deadlocks If a resource allocation graph contains no cycles ⇒ no deadlock If a resource allocation graph contains a cycle and if only one instance exists per resource type ⇒ deadlock If a resource allocation graph contains a cycle and and if several instances exists per resource type ⇒ possibility of deadlock
  • 15. 7.3 Methods for Handling7.3 Methods for Handling DeadlocksDeadlocks
  • 16. Methods for Handling DeadlocksMethods for Handling Deadlocks Prevention Ensure that the system will never enter a deadlock state Avoidance Ensure that the system will never enter an unsafe state Detection Allow the system to enter a deadlock state and then recover Do Nothing Ignore the problem and let the user or system administrator respond to the problem; used by most operating systems, including Windows and UNIX
  • 17. 7.4 Deadlock Prevention7.4 Deadlock Prevention
  • 18. Deadlock PreventionDeadlock Prevention Mutual Exclusion – The mutual-exclusion condition must hold for non-sharable resources Hold and Wait – we must guarantee that whenever a process requests a resource, it does not hold any other resources Require a process to request and be allocated all its resources before it begins execution, or allow a process to request resources only when the process has none Result: Low resource utilization; starvation possible To prevent deadlock, we can restrain the ways that a request can be made
  • 19. Deadlock Prevention (Cont.)Deadlock Prevention (Cont.) No Preemption – If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released Preempted resources are added to the list of resources for which the process is waiting A process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. For example: F(tape drive) = 1 F(disk drive) = 5 F(printer) = 12
  • 20. 7.5 Deadlock Avoidance7.5 Deadlock Avoidance
  • 21. Deadlock AvoidanceDeadlock Avoidance Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition A resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes Requires that the system has some additional a priori information available. a priori: formed or conceived beforehand
  • 22. Safe StateSafe State When a process requests an available resource, the system must decide if immediate allocation leaves the system in a safe state A system is in a safe state only if there exists a safe sequence A sequence of processes <P1, P2, …, Pn> is a safe sequence for the current allocation state if, for each Pi, the resource requests that Pi can still make, can be satisfied by currently available resources plus resources held by all Pj, with j < i. That is: If the 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
  • 23. Safe State (continued)Safe State (continued) 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
  • 24. Safe, Unsafe , Deadlock StateSafe, Unsafe , Deadlock State
  • 25. Avoidance algorithmsAvoidance algorithms For a single instance of a resource type, use a resource- allocation graph For multiple instances of a resource type, use the banker’s algorithm
  • 26. Resource-Allocation Graph SchemeResource-Allocation Graph Scheme Introduce a new kind of edge called a claim edge Claim edge Pi Rj indicates that process Pj may request resource Rj; which is represented by a dashed line A claim edge converts to a request edge when a process requests a resource A request edge converts to an assignment edge when the resource is allocated to the process When a resource is released by a process, an assignment edge reconverts to a claim edge Resources must be claimed a priori in the system
  • 27. Resource-Allocation Graph withResource-Allocation Graph with Claim EdgesClaim Edges Request edge Assignment edge Claim edge Claim edge
  • 28. Unsafe State In Resource-Allocation GraphUnsafe State In Resource-Allocation Graph Assignment edge Request edge Assignment edgeClaim edge
  • 29. Resource-Allocation Graph AlgorithmResource-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
  • 30. Banker’s AlgorithmBanker’s Algorithm Used when there exists multiple instances of a resource type 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
  • 31. Data Structures for the Banker’sData Structures for the Banker’s AlgorithmAlgorithm Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj. Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j] Let n = number of processes, and m = number of resources types.
  • 32. 7.6 Deadlock Detection7.6 Deadlock Detection
  • 33. Deadlock DetectionDeadlock Detection For deadlock detection, the system must provide An algorithm that examines the state of the system to detect whether a deadlock has occurred And an algorithm to recover from the deadlock A detection-and-recovery scheme requires various kinds of overhead Run-time costs of maintaining necessary information and executing the detection algorithm Potential losses inherent in recovering from a deadlock
  • 34. Single Instance of Each ResourceSingle Instance of Each Resource TypeType Requires the creation and maintenance of a wait-for graph Consists of a variant of the resource-allocation graph The graph is obtained by removing the resource nodes from a resource-allocation graph and collapsing the appropriate edges Consequently; all 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
  • 35. Resource-Allocation Graph and Wait-forResource-Allocation Graph and Wait-for GraphGraph Resource-Allocation Graph Corresponding wait-for graph
  • 36. Multiple Instances of a ResourceMultiple Instances of a Resource TypeType 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. Required data structures:
  • 37. Detection-Algorithm UsageDetection-Algorithm Usage When, and how often, to invoke the detection algorithm depends on: How often is a deadlock likely to occur? How many processes will be affected by deadlock when it happens? If the detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which one of the many deadlocked processes “caused” the deadlock If the detection algorithm is invoked for every resource request, such an action will incur a considerable overhead in computation time A less expensive alternative is to invoke the algorithm when CPU utilization drops below 40%, for example This is based on the observation that a deadlock eventually cripples system throughput and causes CPU utilization to drop
  • 38. 7.7 Recovery From Deadlock7.7 Recovery From Deadlock
  • 39. Recovery from DeadlockRecovery from Deadlock Two Approaches Process termination Resource preemption
  • 40. Recovery from Deadlock:Recovery from Deadlock: Process TerminationProcess Termination Abort all deadlocked processes This approach will break the deadlock, but at great expense Abort one process at a time until the deadlock cycle is eliminated This approach incurs considerable overhead, since, after each process is aborted, a deadlock-detection algorithm must be re-invoked to determine whether any processes are still deadlocked Many factors may affect which process is chosen for termination What is the priority of the process? How long has the process run so far and how much longer will the process need to run before completing its task? How many and what type of resources has the process used? How many more resources does the process need in order to finish its task? How many processes will need to be terminated? Is the process interactive or batch?
  • 41. Recovery from Deadlock:Recovery from Deadlock: ResourceResource PreemptionPreemption With this approach, we successively preempt some resources from processes and give these resources to other processes until the deadlock cycle is broken When preemption is required to deal with deadlocks, then three issues need to be addressed: Selecting a victim – Which resources and which processes are to be preempted? Rollback – If we preempt a resource from a process, what should be done with that process? Starvation – How do we ensure that starvation will not occur? That is, how can we guarantee that resources will not always be preempted from the same process?
  • 42. SummarySummary Four necessary conditions must hold in the system for a deadlock to occur Mutual exclusion Hold and wait No preemption Circular wait Four principal methods for dealing with deadlocks Use some protocol to (1) prevent or (2) avoid deadlocks, ensuring that the system will never enter a deadlock state Allow the system to enter a deadlock state, (3) detect it, and then recover  Recover by process termination or resource preemption (4) Do nothing; ignore the problem altogether and pretend that deadlocks never occur in the system (used by Windows and Unix) To prevent deadlocks, we can ensure that at least one of the four necessary conditions never holds
  • 43. REFRENCESREFRENCES Operating System Concepts – 9th Edition By Silberchatz, Galvin and Gagne