SlideShare a Scribd company logo
1 of 52
Instructor
Mr. S.Christalin Nelson
Deadlocks
System Model (1/5)
• System consists of finite resources
• The resources may
– Physical resources
• Example: printers, tape drives, memory space, CPU cycles
– Logical resources
• Example: semaphores, mutex locks, files
• Resource types/classes & Resource Instances
– Resource classes should be defined appropriately
• Example: CPU cycles, memory space, I/O devices, etc.
– Each resource type Ri has Wi instances
4/8/2022 3 of 52
Instructor: Mr.S.Christalin Nelson
System Model (2/5)
• Example-1
– System has 2 CPUS. i.e. Resource type CPU has 2 instances
– If process requests resource type CPU => any instance of this
type can be allocated
• Example-2
– System with resource type Printer has 2 instances (Basement
& Floor-9)
– If process requests resource type printer => Can any instance
be allocated?
4/8/2022 4 of 52
Instructor: Mr.S.Christalin Nelson
System Model (3/5)
• Process resource utilization sequence
– (1) Request, (2) Use , (3) Release
– (1) & (3) may be system calls
• Examples:
– request() and release() device
» semaphore: wait(), signal()
» mutex lock: acquire(), release()
– open() and close() file
– allocate() and free() memory
• System Table (OS records free/allocated resources) & Queue
4/8/2022 5 of 52
Instructor: Mr.S.Christalin Nelson
System Model (4/5)
• Deadlock?
– A set of processes is deadlocked when every process in the set
is waiting for an event (resource acquisition/release) that can
be caused only by another process in the set
• Processes never finish => System resources are tied-up => other
jobs prevented from starting
4/8/2022 6 of 52
Instructor: Mr.S.Christalin Nelson
System Model (5/5)
• Illustration-1: Deadlock involving same resource type
– A system has 2 CD-RW drives & 2 processes (P1 & P2)
– Each process holds 1 CD-RW drive
– If P1 & P2 requests for one more drive => Deadlock occurs
• Illustration-2: deadlock involving different resource type
– A system has 1 printer, 1 DVD drive & 2 processes (P1 & P2)
– P1 holds DVD drive & Process-2 holds printer
– If P1 requests printer & P2 requests DVD drive => Deadlock
occurs
4/8/2022 7 of 52
Instructor: Mr.S.Christalin Nelson
Necessary Conditions for Deadlock
• The following conditions are not completely independent
– (1) Mutual exclusion
– (2) Hold and wait
– (3) No preemption
– (4) Circular wait
4/8/2022 9 of 52
Instructor: Mr.S.Christalin Nelson
Resource allocation graph (1/3)
• Describes Deadlock using Directed Graph
• Graph (G)
– Defined as set (V, E)
– V = {V1, V2, ..., Vn}
– E = {E1, E2, ..., En}
• For a Resource allocation graph (RAG)
– V = {P, R}
• Set of Active Processes, P = {P1, P2, ..., Pn}
• Set of Resources Types, R = {R1, R2, ..., Rn}
– E = Set of Directed edges
• Ei can be Request edge or Assignment edge
– Pi -> Rj (Pi requested for Rj & waits for it)
– Ri -> Pj (Pi’s request accepted & Ri is allocated to Pj)
4/8/2022 10 of 52
Instructor: Mr.S.Christalin Nelson
Resource allocation graph (2/3)
• Notation
– Circle (Process), Rectangle (Resource type), Dot in rectangle
(Resource instance)
– Request edge (Pi-> Rj)
• Edge points to a rectangle
– Assignment edge (Ri -> Pj)
• Edge designates one dot in rectangle
4/8/2022
Resource Instances &
Process States?
11 of 52
Instructor: Mr.S.Christalin Nelson
Resource allocation graph (3/3)
• RAG can contain a cycle
– If no cycle => No deadlock
– If cycle exists => Deadlock may or may not exist
• If each resource has one instance (Necessary & sufficient
condition) deadlock exists
• If each resource has >1 instance (Necessary & not sufficient
condition) deadlock may exists
• Example
– Two cycles
4/8/2022 12 of 52
Instructor: Mr.S.Christalin Nelson
Methods to handle Deadlock (1/2)
• Ensure system never enters deadlock state -> Deadlock
prevention/avoidance
– Deadlock prevention
• One necessary condition not satisfied
– Deadlock avoidance
• Prior information on resource which process can request/use in
its lifetime required -> OS decides whether current request is
satisfied/delayed (i.e. Consider available resources, allocated
resources & future requests and releases)
• Allow system to enter deadlock state & recover -> Deadlock
detection & recovery
• Ignore problem & pretend that deadlocks never occur in
system -> handled by application developer (Used by UNIX &
Windows)
4/8/2022 14 of 52
Instructor: Mr.S.Christalin Nelson
Methods to handle Deadlock (2/2)
• Overhead for Deadlock detection and Recovery
– Run-time costs of maintaining necessary information &
executing detection algorithm
– Potential losses inherent in recovering from a deadlock
4/8/2022 15 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (1/8)
• Mutual exclusion condition
– Should be satisfied (cannot be denied)
– Sharable resources do not require mutually exclusive access &
not involved in a deadlock.
• Example: Read-only files
– Some resources (at least one) are non-sharable
• Example: mutex lock
4/8/2022 17 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (2/8)
• Hold and Wait condition
– To deny, guarantee that when a process requests a resource it
does not hold any other resources
• Solution-1: Process can execute only after its gets all resources
requested. i.e System calls requesting resources for a process
precede all other system calls
• Solution-2: Process can request resources only after releasing all
currently allocated resources
– (Soln. 1 vs. 2) Illustration: P1 copies data from DVD drive to a
file on disk, sorts file, and prints results to a printer
• Solution-1: P1 requests & holds DVD drive, disk file, and printer
for its entire execution. Note: Printer required only at the end
• Solution-2: P1 requests & holds DVD and Disk File to perform
copy => Release both => Requests Disk File & sorts => Requests
Disk File & Printer to print
4/8/2022 18 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (3/8)
• Hold and Wait condition (contd.)
– Disadvantages of both solutions
• (1) Low resource utilization
– Allocated resources are unused for a long period
• (2) Starvation
– At least one resource is always allocated to another process
4/8/2022 19 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (4/8)
• No preemption of already allocated resources
– To deny the condition
• Solution-1: P1 requests for resources -> Some resources are
allocated to P1 & few are held by other processes -> Preempt all
resources from P1 & add to resource waiting list -> P1 restarts
after getting all resources
• Solution-2: P1 requests for resources -> Some resources are
allocated to P1 & few are held by P2 -> Check if P2 is waiting for
new resource -> If yes, preempt desired resources from P2 &
allocate to P1 -> If no, P1 waits -> During wait other acquired
resources may be preempted if requested by other process -> P1
restarts after getting all resources
– Note:
• Cannot be applied to resources (mutex locks, semaphores)
• Applied to resources whose state can be easily saved & restored
later (CPU registers, Memory space).
4/8/2022 20 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (5/8)
• Circular Wait
– To deny this condition
• Total ordering of all resource types & Process should request
resources in an increasing order of enumeration.
– Illustration: Let set of resource types, R = {R1, R2, ..., Rm}
» Assign unique integer no. to each resource type. i.e Define a
one-to-one function F: R→N, where N = set of natural numbers
» Compare two resources & determine whether one precedes
another in ordering.
• Function F is based on normal order of usage of system resources
– Example: If tape drive is usually needed before printer, define
F(tape drive) < F(printer)
4/8/2022 21 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (6/8)
• Circular Wait (contd.)
– Example
• R = {tape drives, disk drives, printers}
• Define F as follows:
– F(tape drive) = 1
– F(disk drive) = 5
– F(printer) = 12
• Solution: If a process wants tape drive & printer at same time
– Using F, it request tape drive & then printer
– Process requesting an instance of Rj must have released any
resources Ri such that F(Ri) ≥ F(Rj)
• Note: A single request is required if several instances of same
resource type are needed
4/8/2022 22 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (7/8)
• Circular Wait (contd.)
– “Circular wait is eliminated” - Proof by contradiction
• Assume circular wait exists
• Processes {P0, P1, ..., Pn} are involved in circular wait such that
– Pi is waiting for Ri, which is held by process Pi+1
– Pn is waiting for a resource Rn held by P0
– Pi+1 is holding resource Ri while requesting resource Ri+1
• Hence, F(Ri+1) > F(Ri) for all i
– Which means F(R0) < F(R1) < ... < F(Rn) < F(R0)
– By transitivity, F(R0) < F(R0) is impossible
• Therefore, there can be no circular wait
4/8/2022 23 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention (8/8)
• Using with application program
– Develop an ordering of all synchronization objects in system
– Application developers write programs to ensure that
resources are acquired in proper order
– Requests for synchronization objects made in increasing order
• Verification & Warning software
– Used to check ordering & when locks are acquired out of order
and deadlock is possible
– Example: Witness
• Lock-order verifier for BSD versions of UNIX such as FreeBSD
• Uses mutual-exclusion locks to protect critical sections
• Note: Imposing lock ordering does not guarantee deadlock
prevention if locks can be acquired dynamically
4/8/2022 24 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Avoidance Vs. Prevention
• Deadlock prevention works by limiting how requests can be
made.
– i.e Ensure at least one of necessary conditions for deadlock
cannot occur.
• Side effects of Deadlock Prevention
– Low device utilization
– Reduced system throughput
• Deadlock avoidance
– System has knowledge (additional information) of complete
sequence of requests & releases for each process & can decide
• Example: A system has one tape drive & one printer. System
knows P will request tape drive first & then printer, before
releasing both. Q will request printer first & then the tape drive
4/8/2022 26 of 52
Instructor: Mr.S.Christalin Nelson
Algorithms
• Approaches can differ in amount & type of information
required
• Simplest & most useful model
– Process declares required max. no. of resources of each type
• Should be <= max. resources in system
• Given this a priori information, algorithm can ensure that system
will never enter deadlocked state
• Ensure circular-wait condition does not exist by dynamic
examination of resource-allocation state
– Resource allocation state: No. of available & allocated
resources, max. demands of processes
4/8/2022 27 of 52
Instructor: Mr.S.Christalin Nelson
Safe & Unsafe State (1/2)
• Safe State
– System can allocate resources to each process (up to max.) in
some order & still avoid a deadlock
– Safe sequence of processes <P1, P2, ..., Pn> for current
allocation state exists
• Resource requests of Pi is satisfied by currently available
resources + resources held by all Pj and j<i
– If resources are not immediately available -> Pi waits until all Pj have
finished -> When finished, Pi obtains all its needed resources,
complete task, return allocated resources, and terminate -> When Pi
terminates, Pi+1 obtains its needed resources -> ….
4/8/2022 28 of 52
Instructor: Mr.S.Christalin Nelson
Safe & Unsafe State (2/2)
• Unsafe state
– Behavior of processes controls unsafe states
– OS cannot prevent processes from requesting resources in
such a way that a deadlock occurs
– May lead to a deadlocked state
• Note: Not all unsafe states are deadlocks
– Depicted as a Cycle in RAG
4/8/2022 29 of 52
Instructor: Mr.S.Christalin Nelson
Avoidance Algorithms
• Single instance of a resource type
– Resource-allocation graph (RAG)
• Multiple instances of a resource type
– Banker’s algorithm
• Less efficient than RAG scheme
4/8/2022 30 of 52
Instructor: Mr.S.Christalin Nelson
RAG Algorithm (1/2)
• Include Claim edge Pi → Rj (Notation: dashed line)
– Pi may request Rj in future
• All claim edges should be known a priori (before execution)
– Variant: Known a priori if all edges of Pi are claim edges
4/8/2022 31 of 52
Instructor: Mr.S.Christalin Nelson
RAG Algorithm (2/2)
• On request: Claim edge is converted to Request edge
• On allocation: Request edge is converted to Assignment
edge
– Cycle is not formed in RAG to ensure safe state
– Cycle Detection algorithm requires n2 operation for ‘n’
processes
– On release: Assignment edge is converted to Claim edge
4/8/2022
cycle
32 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (1/7)
• New process entering system should declare max. no. of
instances of each resource type required
• Resource allocations occur only if safe state exists
– Else, process waits required resources are released
• Data Structures
– Encode resource-allocation state
– For 'n' processes & 'm' resources types
• Available[m] – Vector mentioning the availability of resources
• Max[n][m] – Matrix mentioning the demands of processes
• Allocation[n][m] – Matrix mentioning the allocation to processes
• Need[n][m] – Matrix mentioning the additional requirement of
processes
4/8/2022 33 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (2/7)
• Data structures (contd.)
– Size & value of Data structures can vary over time
– Note:
• Consider each row of matrix as vector denoted as Allocationi &
Needi
4/8/2022
S.No. Example Remarks
1 Available[j] = k ‘k’ instances of resource type ‘Rj’ is available
2 Max[i][j] = k ‘k’ instances of resource type ‘Rj’ is required by process Pi
3 Allocation[i][j] = k ‘k’ instances of resource type ‘Rj’ is allocated to process Pi
4 Need[i][j] = k
‘k’ instances of resource type ‘Rj’ is needed by process Pi
Need[i][j] = Max[i][j] - Allocation[i][j]
34 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (3/7)
• Safety algorithm
– To find if System is in Safe state
• (1) Let Work & Finish be vectors of length m & n, respectively.
Initialize Work = Available, Finish[i] = false for i = 0, 1, ..., n-1
• (2) Find an index i such that Finish[i] == false & Needi ≤ Work
– (2a) If i exists
» Work = Work + Allocationi
» Finish[i] = true, Go to next i
– (2b) Else if no such i exists
» If Finish[i] == true for all i, then system is in a safe state
– Note:
• Requires order of m x n2 operations
4/8/2022 35 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (4/7)
• Resource Request algorithm
– Grant requests safely
• (1) Requesti is request vector for Pi
– Pi wants k instances of Rj if Requesti[ j] == k
• (2) Actions taken when Pi requests for resource
– (a) If Requesti ≤ Needi go to step (2a)
Else, raise error condition (Process has exceeded its max. claim)
– (b) If Requesti ≤ Available go to step (2c)
Else, Pi must wait as resources are unavailable
– (c) System pretends to allocate resources to Pi by modifying state
» Available =Available - Requesti and Needi = Needi - Requesti
» Allocationi = Allocationi + Requesti
• If resource-allocation state is safe, Pi is allocated its resources &
Transaction completed. Else Pi waits for Requesti & old resource-
allocation state restored
4/8/2022 36 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (5/7)
• Example
– A system has 5 processes (P0, P1, P2, P3 & P4), and 3 resource
types (A, B, C). A has 10 instances, B has 5 instances, and C has
7 instances
– At time T0, consider system snapshot is
4/8/2022
Need?
37 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (6/7)
• Example (contd.)
– Consider system is in safe state with safe sequence <P1, P3, P4,
P2, P0>
– If P1 requests 1 instance of A & 2 instances of C
• i.e. Request1 = (1,0,2). Can request be immediately granted?
– Check Request1 ≤ Available i.e. (1,0,2) ≤ (3,3,2) => true
– Pretend that this request has been fulfilled & resulting state is:
4/8/2022
Request1 = (1,0,2)
38 of 52
Instructor: Mr.S.Christalin Nelson
Banker’s Algorithm (7/7)
• Example (contd.)
– Check if above new system state is safe using safety algorithm
• Find safe sequence. We get <P1, P3, P4, P0, P2>. Hence,
immediately grant request of P1
– Further
• Request for (3,3,0) by P4 cannot be granted, since resources are
unavailable
• Request for (0,2,0) by P0 cannot be granted, though resources are
available but resulting state is unsafe
4/8/2022
How?
39 of 52
Instructor: Mr.S.Christalin Nelson
All resources have single Instance (1/2)
• Convert RAG to WFG
– Remove resource nodes & collapse appropriate edges
• i.e. An edge from Pi -> Pj in WFG => Pi is waiting for process Pj to
release a resource that Pi needs
• An edge Pi → Pj exists in WFG iff corresponding RAG has 2 edges
Pi → Rq & Rq → Pj for Rq
4/8/2022 41 of 52
Instructor: Mr.S.Christalin Nelson
All resources have single Instance (2/2)
• Deadlock exists iff WFG contains a cycle
– System maintains WFG & periodically invoke an Cycle
detection algorithm (requires an order of n2 operations for 'n'
vertices in graph)
• Not applicable when multiple instances of each resource
type exist
4/8/2022 42 of 52
Instructor: Mr.S.Christalin Nelson
Several Instances of a Resource Type (1/4)
• Data structures used (Similar to Banker's algorithm Slide#33)
– For 'n' processes & 'm' resources types
• Available[m] – Vector mentioning availability of resources
• Allocation[n][m] – Matrix mentioning allocation to processes
• Request[n][m] – Matrix mentioning requests of processes
– Size & value of Data structures can vary over time
– Note:
• Consider each row of matrix as vector denoted as Allocationi &
Requesti
4/8/2022 43 of 52
Instructor: Mr.S.Christalin Nelson
Several Instances of a Resource Type (2/4)
• Algorithm
– (1) Let Work & Finish be vectors of length m & n, respectively
• Initialize:
– Work = Available
– For i = 0, 1, ..., n–1
» If Allocationi != 0, Finish[i] = false. Else, Finish[i] = true
– (2) Find index i such that Finish[i] == false & Requesti ≤ Work
• (2a) If i exists
– Work = Work + Allocationi
– Finish[i] = true, Go to next i
• (2b) Else if no such i exists
– If Finish[i] == false for some i, 0≤i<n, then Pi is deadlocked (System is
in deadlocked state)
– Note: Requires order of m x n2 operations
4/8/2022 44 of 52
Instructor: Mr.S.Christalin Nelson
Several Instances of a Resource Type (3/4)
• Example
– A system has 5 processes (P0, P1, P2, P3 & P4), and 3 resource
types (A, B, C). A has 7 instances, B has 2 instances, and C has 6
instances
– At time T0, consider resource allocation state (RAS)
• System is not in deadlocked state as Safe sequence <P0, P2, P3,
P1, P4> results in Finish[i] == true for all i
4/8/2022 45 of 52
Instructor: Mr.S.Christalin Nelson
Several Instances of a Resource Type (4/4)
• Example (contd.)
– P2 makes additional request for 1 instance of C. The modified
Request matrix is
• System is deadlocked (consists processes P1, P2, P3, and P4)
– Though resources held by P0 can be reclaimed, no. of available
resources is insufficient to fulfill requests of other processes
4/8/2022 46 of 52
Instructor: Mr.S.Christalin Nelson
Usage (1/2)
• Factors to decide invocation of deadlock detection
– (1) How frequent is a deadlock likely to occur?
• If frequent -> Invoke detection algorithm frequently
– (2) How many processes will be affected by deadlock when it
happens?
• Resources allocated to deadlocked processes will be idle until
deadlock can be broken
• No. of processes involved in deadlock cycle may grow
• Deadlocks occur when a process makes a request (final
request makes a cycle) that cannot be granted immediately
– Deadlocked processes is a link in the cycle
– If there are many different resource types, one request may
create many cycles in the resource graph
4/8/2022 47 of 52
Instructor: Mr.S.Christalin Nelson
Usage (2/2)
• (Extreme) Invoke deadlock detection every time a request
for allocation cannot be granted immediately
– Deadlocked set of processes & specific process that “caused”
deadlock can be identified
• Invoke deadlock-detection for every resource request
– Considerable overhead in computation time
• Invoke deadlock-detection at defined intervals at arbitrary
points in time (once per hr. or whenever CPU utilization
drops below 40%)
– Resource graph may contain many cycles
– The deadlocked processes which “caused” deadlock cannot be
identified
4/8/2022 48 of 52
Instructor: Mr.S.Christalin Nelson
Process Termination
• Abort all deadlocked processes
• Abort one process at a time until the deadlock cycle is
eliminated
• In which order should we choose to abort?
– 1. Priority of the process
– 2. How long process has computed, and how much longer to
completion
– 3. Resources the process has used
– 4. Resources process needs to complete
– 5. How many processes will need to be terminated
– 6. Is process interactive or batch?
4/8/2022 50 of 52
Instructor: Mr.S.Christalin Nelson
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
4/8/2022 51 of 52
Instructor: Mr.S.Christalin Nelson
Deadlock Prevention Methods

More Related Content

What's hot

Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device DriverGary Yeh
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementationsangrampatil81
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux TroubleshootingKeith Wright
 
11 distributed file_systems
11 distributed file_systems11 distributed file_systems
11 distributed file_systemslongly
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksMukesh Chinta
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingScyllaDB
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver艾鍗科技
 
Gestion Procesos, Sistemas Operativos
Gestion Procesos, Sistemas OperativosGestion Procesos, Sistemas Operativos
Gestion Procesos, Sistemas OperativosMarvin Romero
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VRISC-V International
 
Scheduler activations
Scheduler activationsScheduler activations
Scheduler activationsVin Voro
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating SystemSanthiNivas
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithmssathish sak
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driverVandana Salve
 
Introduction to RTOS
Introduction to RTOSIntroduction to RTOS
Introduction to RTOSYong Heui Cho
 
Chapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File SystemsChapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File Systemsaskme
 

What's hot (20)

Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
Linux scheduler
Linux schedulerLinux scheduler
Linux scheduler
 
Linux Memory Management
Linux Memory ManagementLinux Memory Management
Linux Memory Management
 
Network Drivers
Network DriversNetwork Drivers
Network Drivers
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementation
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
11 distributed file_systems
11 distributed file_systems11 distributed file_systems
11 distributed file_systems
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
New Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using TracingNew Ways to Find Latency in Linux Using Tracing
New Ways to Find Latency in Linux Using Tracing
 
Linux device drivers
Linux device driversLinux device drivers
Linux device drivers
 
Linux Ethernet device driver
Linux Ethernet device driverLinux Ethernet device driver
Linux Ethernet device driver
 
Gestion Procesos, Sistemas Operativos
Gestion Procesos, Sistemas OperativosGestion Procesos, Sistemas Operativos
Gestion Procesos, Sistemas Operativos
 
Static partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-VStatic partitioning virtualization on RISC-V
Static partitioning virtualization on RISC-V
 
Scheduler activations
Scheduler activationsScheduler activations
Scheduler activations
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Operating Systems Process Scheduling Algorithms
Operating Systems   Process Scheduling AlgorithmsOperating Systems   Process Scheduling Algorithms
Operating Systems Process Scheduling Algorithms
 
Introduction to char device driver
Introduction to char device driverIntroduction to char device driver
Introduction to char device driver
 
Introduction to RTOS
Introduction to RTOSIntroduction to RTOS
Introduction to RTOS
 
Chapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File SystemsChapter 9: SCSI Drives and File Systems
Chapter 9: SCSI Drives and File Systems
 

Similar to Deadlock Prevention Methods

Similar to Deadlock Prevention Methods (20)

OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
7308346-Deadlock.pptx
7308346-Deadlock.pptx7308346-Deadlock.pptx
7308346-Deadlock.pptx
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
chapter06-new.pptx
chapter06-new.pptxchapter06-new.pptx
chapter06-new.pptx
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 
Deadlocks
Deadlocks Deadlocks
Deadlocks
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCK
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlocks1
Deadlocks1Deadlocks1
Deadlocks1
 
3 (2).ppt
3 (2).ppt3 (2).ppt
3 (2).ppt
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
Deadlocks2
Deadlocks2Deadlocks2
Deadlocks2
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
Deadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWDDeadlock_SVVSDM_DWD
Deadlock_SVVSDM_DWD
 
O ssvv62015
O ssvv62015O ssvv62015
O ssvv62015
 
deadlock and starvation resources allocation.pptx
deadlock and starvation resources allocation.pptxdeadlock and starvation resources allocation.pptx
deadlock and starvation resources allocation.pptx
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 

More from Christalin Nelson

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfChristalin Nelson
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfChristalin Nelson
 
Relational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfRelational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfChristalin Nelson
 
Data Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdfData Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdfChristalin Nelson
 
Data Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfData Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfChristalin Nelson
 
Overview of Databases and Data Modelling-2.pdf
Overview of Databases and Data Modelling-2.pdfOverview of Databases and Data Modelling-2.pdf
Overview of Databases and Data Modelling-2.pdfChristalin Nelson
 
Overview of Databases and Data Modelling-1.pdf
Overview of Databases and Data Modelling-1.pdfOverview of Databases and Data Modelling-1.pdf
Overview of Databases and Data Modelling-1.pdfChristalin Nelson
 
Packages and Subpackages in Java
Packages and Subpackages in JavaPackages and Subpackages in Java
Packages and Subpackages in JavaChristalin Nelson
 
Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2Christalin Nelson
 
Data Storage and Information Management
Data Storage and Information ManagementData Storage and Information Management
Data Storage and Information ManagementChristalin Nelson
 
Application Middleware Overview
Application Middleware OverviewApplication Middleware Overview
Application Middleware OverviewChristalin Nelson
 

More from Christalin Nelson (20)

Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
DiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdfDiskStorage_BasicFileStructuresandHashing.pdf
DiskStorage_BasicFileStructuresandHashing.pdf
 
DBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdfDBMSArchitecture_QueryProcessingandOptimization.pdf
DBMSArchitecture_QueryProcessingandOptimization.pdf
 
Relational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdfRelational_Algebra_Calculus Operations.pdf
Relational_Algebra_Calculus Operations.pdf
 
Data Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdfData Modeling - Enhanced ER diagrams & Mapping.pdf
Data Modeling - Enhanced ER diagrams & Mapping.pdf
 
Data Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdfData Modeling - Entity Relationship Diagrams-1.pdf
Data Modeling - Entity Relationship Diagrams-1.pdf
 
Overview of Databases and Data Modelling-2.pdf
Overview of Databases and Data Modelling-2.pdfOverview of Databases and Data Modelling-2.pdf
Overview of Databases and Data Modelling-2.pdf
 
Overview of Databases and Data Modelling-1.pdf
Overview of Databases and Data Modelling-1.pdfOverview of Databases and Data Modelling-1.pdf
Overview of Databases and Data Modelling-1.pdf
 
Packages and Subpackages in Java
Packages and Subpackages in JavaPackages and Subpackages in Java
Packages and Subpackages in Java
 
Bitwise complement operator
Bitwise complement operatorBitwise complement operator
Bitwise complement operator
 
Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2Advanced Data Structures - Vol.2
Advanced Data Structures - Vol.2
 
Applications of Stack
Applications of StackApplications of Stack
Applications of Stack
 
Data Storage and Information Management
Data Storage and Information ManagementData Storage and Information Management
Data Storage and Information Management
 
Application Middleware Overview
Application Middleware OverviewApplication Middleware Overview
Application Middleware Overview
 
Network security
Network securityNetwork security
Network security
 
Directory services
Directory servicesDirectory services
Directory services
 
System overview
System overviewSystem overview
System overview
 
Storage overview
Storage overviewStorage overview
Storage overview
 

Recently uploaded

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 

Deadlock Prevention Methods

  • 2.
  • 3. System Model (1/5) • System consists of finite resources • The resources may – Physical resources • Example: printers, tape drives, memory space, CPU cycles – Logical resources • Example: semaphores, mutex locks, files • Resource types/classes & Resource Instances – Resource classes should be defined appropriately • Example: CPU cycles, memory space, I/O devices, etc. – Each resource type Ri has Wi instances 4/8/2022 3 of 52 Instructor: Mr.S.Christalin Nelson
  • 4. System Model (2/5) • Example-1 – System has 2 CPUS. i.e. Resource type CPU has 2 instances – If process requests resource type CPU => any instance of this type can be allocated • Example-2 – System with resource type Printer has 2 instances (Basement & Floor-9) – If process requests resource type printer => Can any instance be allocated? 4/8/2022 4 of 52 Instructor: Mr.S.Christalin Nelson
  • 5. System Model (3/5) • Process resource utilization sequence – (1) Request, (2) Use , (3) Release – (1) & (3) may be system calls • Examples: – request() and release() device » semaphore: wait(), signal() » mutex lock: acquire(), release() – open() and close() file – allocate() and free() memory • System Table (OS records free/allocated resources) & Queue 4/8/2022 5 of 52 Instructor: Mr.S.Christalin Nelson
  • 6. System Model (4/5) • Deadlock? – A set of processes is deadlocked when every process in the set is waiting for an event (resource acquisition/release) that can be caused only by another process in the set • Processes never finish => System resources are tied-up => other jobs prevented from starting 4/8/2022 6 of 52 Instructor: Mr.S.Christalin Nelson
  • 7. System Model (5/5) • Illustration-1: Deadlock involving same resource type – A system has 2 CD-RW drives & 2 processes (P1 & P2) – Each process holds 1 CD-RW drive – If P1 & P2 requests for one more drive => Deadlock occurs • Illustration-2: deadlock involving different resource type – A system has 1 printer, 1 DVD drive & 2 processes (P1 & P2) – P1 holds DVD drive & Process-2 holds printer – If P1 requests printer & P2 requests DVD drive => Deadlock occurs 4/8/2022 7 of 52 Instructor: Mr.S.Christalin Nelson
  • 8.
  • 9. Necessary Conditions for Deadlock • The following conditions are not completely independent – (1) Mutual exclusion – (2) Hold and wait – (3) No preemption – (4) Circular wait 4/8/2022 9 of 52 Instructor: Mr.S.Christalin Nelson
  • 10. Resource allocation graph (1/3) • Describes Deadlock using Directed Graph • Graph (G) – Defined as set (V, E) – V = {V1, V2, ..., Vn} – E = {E1, E2, ..., En} • For a Resource allocation graph (RAG) – V = {P, R} • Set of Active Processes, P = {P1, P2, ..., Pn} • Set of Resources Types, R = {R1, R2, ..., Rn} – E = Set of Directed edges • Ei can be Request edge or Assignment edge – Pi -> Rj (Pi requested for Rj & waits for it) – Ri -> Pj (Pi’s request accepted & Ri is allocated to Pj) 4/8/2022 10 of 52 Instructor: Mr.S.Christalin Nelson
  • 11. Resource allocation graph (2/3) • Notation – Circle (Process), Rectangle (Resource type), Dot in rectangle (Resource instance) – Request edge (Pi-> Rj) • Edge points to a rectangle – Assignment edge (Ri -> Pj) • Edge designates one dot in rectangle 4/8/2022 Resource Instances & Process States? 11 of 52 Instructor: Mr.S.Christalin Nelson
  • 12. Resource allocation graph (3/3) • RAG can contain a cycle – If no cycle => No deadlock – If cycle exists => Deadlock may or may not exist • If each resource has one instance (Necessary & sufficient condition) deadlock exists • If each resource has >1 instance (Necessary & not sufficient condition) deadlock may exists • Example – Two cycles 4/8/2022 12 of 52 Instructor: Mr.S.Christalin Nelson
  • 13.
  • 14. Methods to handle Deadlock (1/2) • Ensure system never enters deadlock state -> Deadlock prevention/avoidance – Deadlock prevention • One necessary condition not satisfied – Deadlock avoidance • Prior information on resource which process can request/use in its lifetime required -> OS decides whether current request is satisfied/delayed (i.e. Consider available resources, allocated resources & future requests and releases) • Allow system to enter deadlock state & recover -> Deadlock detection & recovery • Ignore problem & pretend that deadlocks never occur in system -> handled by application developer (Used by UNIX & Windows) 4/8/2022 14 of 52 Instructor: Mr.S.Christalin Nelson
  • 15. Methods to handle Deadlock (2/2) • Overhead for Deadlock detection and Recovery – Run-time costs of maintaining necessary information & executing detection algorithm – Potential losses inherent in recovering from a deadlock 4/8/2022 15 of 52 Instructor: Mr.S.Christalin Nelson
  • 16.
  • 17. Deadlock Prevention (1/8) • Mutual exclusion condition – Should be satisfied (cannot be denied) – Sharable resources do not require mutually exclusive access & not involved in a deadlock. • Example: Read-only files – Some resources (at least one) are non-sharable • Example: mutex lock 4/8/2022 17 of 52 Instructor: Mr.S.Christalin Nelson
  • 18. Deadlock Prevention (2/8) • Hold and Wait condition – To deny, guarantee that when a process requests a resource it does not hold any other resources • Solution-1: Process can execute only after its gets all resources requested. i.e System calls requesting resources for a process precede all other system calls • Solution-2: Process can request resources only after releasing all currently allocated resources – (Soln. 1 vs. 2) Illustration: P1 copies data from DVD drive to a file on disk, sorts file, and prints results to a printer • Solution-1: P1 requests & holds DVD drive, disk file, and printer for its entire execution. Note: Printer required only at the end • Solution-2: P1 requests & holds DVD and Disk File to perform copy => Release both => Requests Disk File & sorts => Requests Disk File & Printer to print 4/8/2022 18 of 52 Instructor: Mr.S.Christalin Nelson
  • 19. Deadlock Prevention (3/8) • Hold and Wait condition (contd.) – Disadvantages of both solutions • (1) Low resource utilization – Allocated resources are unused for a long period • (2) Starvation – At least one resource is always allocated to another process 4/8/2022 19 of 52 Instructor: Mr.S.Christalin Nelson
  • 20. Deadlock Prevention (4/8) • No preemption of already allocated resources – To deny the condition • Solution-1: P1 requests for resources -> Some resources are allocated to P1 & few are held by other processes -> Preempt all resources from P1 & add to resource waiting list -> P1 restarts after getting all resources • Solution-2: P1 requests for resources -> Some resources are allocated to P1 & few are held by P2 -> Check if P2 is waiting for new resource -> If yes, preempt desired resources from P2 & allocate to P1 -> If no, P1 waits -> During wait other acquired resources may be preempted if requested by other process -> P1 restarts after getting all resources – Note: • Cannot be applied to resources (mutex locks, semaphores) • Applied to resources whose state can be easily saved & restored later (CPU registers, Memory space). 4/8/2022 20 of 52 Instructor: Mr.S.Christalin Nelson
  • 21. Deadlock Prevention (5/8) • Circular Wait – To deny this condition • Total ordering of all resource types & Process should request resources in an increasing order of enumeration. – Illustration: Let set of resource types, R = {R1, R2, ..., Rm} » Assign unique integer no. to each resource type. i.e Define a one-to-one function F: R→N, where N = set of natural numbers » Compare two resources & determine whether one precedes another in ordering. • Function F is based on normal order of usage of system resources – Example: If tape drive is usually needed before printer, define F(tape drive) < F(printer) 4/8/2022 21 of 52 Instructor: Mr.S.Christalin Nelson
  • 22. Deadlock Prevention (6/8) • Circular Wait (contd.) – Example • R = {tape drives, disk drives, printers} • Define F as follows: – F(tape drive) = 1 – F(disk drive) = 5 – F(printer) = 12 • Solution: If a process wants tape drive & printer at same time – Using F, it request tape drive & then printer – Process requesting an instance of Rj must have released any resources Ri such that F(Ri) ≥ F(Rj) • Note: A single request is required if several instances of same resource type are needed 4/8/2022 22 of 52 Instructor: Mr.S.Christalin Nelson
  • 23. Deadlock Prevention (7/8) • Circular Wait (contd.) – “Circular wait is eliminated” - Proof by contradiction • Assume circular wait exists • Processes {P0, P1, ..., Pn} are involved in circular wait such that – Pi is waiting for Ri, which is held by process Pi+1 – Pn is waiting for a resource Rn held by P0 – Pi+1 is holding resource Ri while requesting resource Ri+1 • Hence, F(Ri+1) > F(Ri) for all i – Which means F(R0) < F(R1) < ... < F(Rn) < F(R0) – By transitivity, F(R0) < F(R0) is impossible • Therefore, there can be no circular wait 4/8/2022 23 of 52 Instructor: Mr.S.Christalin Nelson
  • 24. Deadlock Prevention (8/8) • Using with application program – Develop an ordering of all synchronization objects in system – Application developers write programs to ensure that resources are acquired in proper order – Requests for synchronization objects made in increasing order • Verification & Warning software – Used to check ordering & when locks are acquired out of order and deadlock is possible – Example: Witness • Lock-order verifier for BSD versions of UNIX such as FreeBSD • Uses mutual-exclusion locks to protect critical sections • Note: Imposing lock ordering does not guarantee deadlock prevention if locks can be acquired dynamically 4/8/2022 24 of 52 Instructor: Mr.S.Christalin Nelson
  • 25.
  • 26. Deadlock Avoidance Vs. Prevention • Deadlock prevention works by limiting how requests can be made. – i.e Ensure at least one of necessary conditions for deadlock cannot occur. • Side effects of Deadlock Prevention – Low device utilization – Reduced system throughput • Deadlock avoidance – System has knowledge (additional information) of complete sequence of requests & releases for each process & can decide • Example: A system has one tape drive & one printer. System knows P will request tape drive first & then printer, before releasing both. Q will request printer first & then the tape drive 4/8/2022 26 of 52 Instructor: Mr.S.Christalin Nelson
  • 27. Algorithms • Approaches can differ in amount & type of information required • Simplest & most useful model – Process declares required max. no. of resources of each type • Should be <= max. resources in system • Given this a priori information, algorithm can ensure that system will never enter deadlocked state • Ensure circular-wait condition does not exist by dynamic examination of resource-allocation state – Resource allocation state: No. of available & allocated resources, max. demands of processes 4/8/2022 27 of 52 Instructor: Mr.S.Christalin Nelson
  • 28. Safe & Unsafe State (1/2) • Safe State – System can allocate resources to each process (up to max.) in some order & still avoid a deadlock – Safe sequence of processes <P1, P2, ..., Pn> for current allocation state exists • Resource requests of Pi is satisfied by currently available resources + resources held by all Pj and j<i – If resources are not immediately available -> Pi waits until all Pj have finished -> When finished, Pi obtains all its needed resources, complete task, return allocated resources, and terminate -> When Pi terminates, Pi+1 obtains its needed resources -> …. 4/8/2022 28 of 52 Instructor: Mr.S.Christalin Nelson
  • 29. Safe & Unsafe State (2/2) • Unsafe state – Behavior of processes controls unsafe states – OS cannot prevent processes from requesting resources in such a way that a deadlock occurs – May lead to a deadlocked state • Note: Not all unsafe states are deadlocks – Depicted as a Cycle in RAG 4/8/2022 29 of 52 Instructor: Mr.S.Christalin Nelson
  • 30. Avoidance Algorithms • Single instance of a resource type – Resource-allocation graph (RAG) • Multiple instances of a resource type – Banker’s algorithm • Less efficient than RAG scheme 4/8/2022 30 of 52 Instructor: Mr.S.Christalin Nelson
  • 31. RAG Algorithm (1/2) • Include Claim edge Pi → Rj (Notation: dashed line) – Pi may request Rj in future • All claim edges should be known a priori (before execution) – Variant: Known a priori if all edges of Pi are claim edges 4/8/2022 31 of 52 Instructor: Mr.S.Christalin Nelson
  • 32. RAG Algorithm (2/2) • On request: Claim edge is converted to Request edge • On allocation: Request edge is converted to Assignment edge – Cycle is not formed in RAG to ensure safe state – Cycle Detection algorithm requires n2 operation for ‘n’ processes – On release: Assignment edge is converted to Claim edge 4/8/2022 cycle 32 of 52 Instructor: Mr.S.Christalin Nelson
  • 33. Banker’s Algorithm (1/7) • New process entering system should declare max. no. of instances of each resource type required • Resource allocations occur only if safe state exists – Else, process waits required resources are released • Data Structures – Encode resource-allocation state – For 'n' processes & 'm' resources types • Available[m] – Vector mentioning the availability of resources • Max[n][m] – Matrix mentioning the demands of processes • Allocation[n][m] – Matrix mentioning the allocation to processes • Need[n][m] – Matrix mentioning the additional requirement of processes 4/8/2022 33 of 52 Instructor: Mr.S.Christalin Nelson
  • 34. Banker’s Algorithm (2/7) • Data structures (contd.) – Size & value of Data structures can vary over time – Note: • Consider each row of matrix as vector denoted as Allocationi & Needi 4/8/2022 S.No. Example Remarks 1 Available[j] = k ‘k’ instances of resource type ‘Rj’ is available 2 Max[i][j] = k ‘k’ instances of resource type ‘Rj’ is required by process Pi 3 Allocation[i][j] = k ‘k’ instances of resource type ‘Rj’ is allocated to process Pi 4 Need[i][j] = k ‘k’ instances of resource type ‘Rj’ is needed by process Pi Need[i][j] = Max[i][j] - Allocation[i][j] 34 of 52 Instructor: Mr.S.Christalin Nelson
  • 35. Banker’s Algorithm (3/7) • Safety algorithm – To find if System is in Safe state • (1) Let Work & Finish be vectors of length m & n, respectively. Initialize Work = Available, Finish[i] = false for i = 0, 1, ..., n-1 • (2) Find an index i such that Finish[i] == false & Needi ≤ Work – (2a) If i exists » Work = Work + Allocationi » Finish[i] = true, Go to next i – (2b) Else if no such i exists » If Finish[i] == true for all i, then system is in a safe state – Note: • Requires order of m x n2 operations 4/8/2022 35 of 52 Instructor: Mr.S.Christalin Nelson
  • 36. Banker’s Algorithm (4/7) • Resource Request algorithm – Grant requests safely • (1) Requesti is request vector for Pi – Pi wants k instances of Rj if Requesti[ j] == k • (2) Actions taken when Pi requests for resource – (a) If Requesti ≤ Needi go to step (2a) Else, raise error condition (Process has exceeded its max. claim) – (b) If Requesti ≤ Available go to step (2c) Else, Pi must wait as resources are unavailable – (c) System pretends to allocate resources to Pi by modifying state » Available =Available - Requesti and Needi = Needi - Requesti » Allocationi = Allocationi + Requesti • If resource-allocation state is safe, Pi is allocated its resources & Transaction completed. Else Pi waits for Requesti & old resource- allocation state restored 4/8/2022 36 of 52 Instructor: Mr.S.Christalin Nelson
  • 37. Banker’s Algorithm (5/7) • Example – A system has 5 processes (P0, P1, P2, P3 & P4), and 3 resource types (A, B, C). A has 10 instances, B has 5 instances, and C has 7 instances – At time T0, consider system snapshot is 4/8/2022 Need? 37 of 52 Instructor: Mr.S.Christalin Nelson
  • 38. Banker’s Algorithm (6/7) • Example (contd.) – Consider system is in safe state with safe sequence <P1, P3, P4, P2, P0> – If P1 requests 1 instance of A & 2 instances of C • i.e. Request1 = (1,0,2). Can request be immediately granted? – Check Request1 ≤ Available i.e. (1,0,2) ≤ (3,3,2) => true – Pretend that this request has been fulfilled & resulting state is: 4/8/2022 Request1 = (1,0,2) 38 of 52 Instructor: Mr.S.Christalin Nelson
  • 39. Banker’s Algorithm (7/7) • Example (contd.) – Check if above new system state is safe using safety algorithm • Find safe sequence. We get <P1, P3, P4, P0, P2>. Hence, immediately grant request of P1 – Further • Request for (3,3,0) by P4 cannot be granted, since resources are unavailable • Request for (0,2,0) by P0 cannot be granted, though resources are available but resulting state is unsafe 4/8/2022 How? 39 of 52 Instructor: Mr.S.Christalin Nelson
  • 40.
  • 41. All resources have single Instance (1/2) • Convert RAG to WFG – Remove resource nodes & collapse appropriate edges • i.e. An edge from Pi -> Pj in WFG => Pi is waiting for process Pj to release a resource that Pi needs • An edge Pi → Pj exists in WFG iff corresponding RAG has 2 edges Pi → Rq & Rq → Pj for Rq 4/8/2022 41 of 52 Instructor: Mr.S.Christalin Nelson
  • 42. All resources have single Instance (2/2) • Deadlock exists iff WFG contains a cycle – System maintains WFG & periodically invoke an Cycle detection algorithm (requires an order of n2 operations for 'n' vertices in graph) • Not applicable when multiple instances of each resource type exist 4/8/2022 42 of 52 Instructor: Mr.S.Christalin Nelson
  • 43. Several Instances of a Resource Type (1/4) • Data structures used (Similar to Banker's algorithm Slide#33) – For 'n' processes & 'm' resources types • Available[m] – Vector mentioning availability of resources • Allocation[n][m] – Matrix mentioning allocation to processes • Request[n][m] – Matrix mentioning requests of processes – Size & value of Data structures can vary over time – Note: • Consider each row of matrix as vector denoted as Allocationi & Requesti 4/8/2022 43 of 52 Instructor: Mr.S.Christalin Nelson
  • 44. Several Instances of a Resource Type (2/4) • Algorithm – (1) Let Work & Finish be vectors of length m & n, respectively • Initialize: – Work = Available – For i = 0, 1, ..., n–1 » If Allocationi != 0, Finish[i] = false. Else, Finish[i] = true – (2) Find index i such that Finish[i] == false & Requesti ≤ Work • (2a) If i exists – Work = Work + Allocationi – Finish[i] = true, Go to next i • (2b) Else if no such i exists – If Finish[i] == false for some i, 0≤i<n, then Pi is deadlocked (System is in deadlocked state) – Note: Requires order of m x n2 operations 4/8/2022 44 of 52 Instructor: Mr.S.Christalin Nelson
  • 45. Several Instances of a Resource Type (3/4) • Example – A system has 5 processes (P0, P1, P2, P3 & P4), and 3 resource types (A, B, C). A has 7 instances, B has 2 instances, and C has 6 instances – At time T0, consider resource allocation state (RAS) • System is not in deadlocked state as Safe sequence <P0, P2, P3, P1, P4> results in Finish[i] == true for all i 4/8/2022 45 of 52 Instructor: Mr.S.Christalin Nelson
  • 46. Several Instances of a Resource Type (4/4) • Example (contd.) – P2 makes additional request for 1 instance of C. The modified Request matrix is • System is deadlocked (consists processes P1, P2, P3, and P4) – Though resources held by P0 can be reclaimed, no. of available resources is insufficient to fulfill requests of other processes 4/8/2022 46 of 52 Instructor: Mr.S.Christalin Nelson
  • 47. Usage (1/2) • Factors to decide invocation of deadlock detection – (1) How frequent is a deadlock likely to occur? • If frequent -> Invoke detection algorithm frequently – (2) How many processes will be affected by deadlock when it happens? • Resources allocated to deadlocked processes will be idle until deadlock can be broken • No. of processes involved in deadlock cycle may grow • Deadlocks occur when a process makes a request (final request makes a cycle) that cannot be granted immediately – Deadlocked processes is a link in the cycle – If there are many different resource types, one request may create many cycles in the resource graph 4/8/2022 47 of 52 Instructor: Mr.S.Christalin Nelson
  • 48. Usage (2/2) • (Extreme) Invoke deadlock detection every time a request for allocation cannot be granted immediately – Deadlocked set of processes & specific process that “caused” deadlock can be identified • Invoke deadlock-detection for every resource request – Considerable overhead in computation time • Invoke deadlock-detection at defined intervals at arbitrary points in time (once per hr. or whenever CPU utilization drops below 40%) – Resource graph may contain many cycles – The deadlocked processes which “caused” deadlock cannot be identified 4/8/2022 48 of 52 Instructor: Mr.S.Christalin Nelson
  • 49.
  • 50. Process Termination • Abort all deadlocked processes • Abort one process at a time until the deadlock cycle is eliminated • In which order should we choose to abort? – 1. Priority of the process – 2. How long process has computed, and how much longer to completion – 3. Resources the process has used – 4. Resources process needs to complete – 5. How many processes will need to be terminated – 6. Is process interactive or batch? 4/8/2022 50 of 52 Instructor: Mr.S.Christalin Nelson
  • 51. 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 4/8/2022 51 of 52 Instructor: Mr.S.Christalin Nelson