0% found this document useful (0 votes)
13 views

Deadlocks

Uploaded by

leekhithnunna369
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Deadlocks

Uploaded by

leekhithnunna369
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Deadlocks

Sanghamitra Mishra
Deadlocks
● Two or more processes wait for a resource or an event which would never happen.
Deadlocks vs Starvation
Deadlock Starvation

● Two or more processes are in the ● Specific process is in the blocked


blocked state forever. state and is denied at least one
● Processes in deadlock hold at least resource.
one resource requested by another ● Processes in starvation may not hold

process also in blocked state any resources requested by another


process
● There is circular waiting
● Could be caused due to some
priority preference to other
processes
Resource Allocation Graph

● Cycle present
● Deadlock
Resource Allocation Graph (contd.)

● Cycle present
● No Deadlock
Necessary and sufficient conditions for Deadlock to occur
1. Mutual Exclusion: Only one process can use a resource at a time

2. Hold & Wait: Every process holds at least 1 resource and waits for another resource

3. Circular wait: A set of processes waiting on each other in a circular manner

4. No-preemption: A resource can only be released if a process releases that resource


Methods for handling Deadlock
1. Deadlock Prevention: Prevent deadlock by dissatisfying one or more of the
necessary conditions

2. Deadlock Ignorance: Restart the whole system (Ostrich Algorithm)

3. Deadlock Avoidance: Banker’s Algorithm

4. Deadlock Detection & Recovery: Detect deadlock, then preempt a resource or


terminate a process
Deadlock Prevention
Deadlock is prevented by dissatisfying one or more of the necessary conditions:

● !(Mutual exclusion)
● !(Hold & Wait)
● !(No-preemption)
● !(Circular wait)
Deadlock Ignorance
● Shut down the system and restart again

● Also called as Ostrich algorithm

● Usually done since occurrence of deadlocks is very rare

● Drawback:

○ Importance processes might be shut down and require to be restarted

○ Could lead to inconsistency of data

● Most commonly used method to handle deadlocks

● OS using this method: Windows, Linux


Deadlock Avoidance
● The system knows about the number of processes, the maximum needs of each process

and the current holdings of each process, the number of resources, total instances of

every resource.

● Not practical, but serves as a benchmark for other methods

● Safe State: A state of no deadlock

● Algorithm used: Banker’s algorithm


Deadlock Detection and Recovery
● Detection (Single instance of a resource type)
○ Run Wait-for-graph
○ Run cycle-detection algo
○ A cycle is a necessary and sufficient condition for deadlock

● Detection (Multiple instance of a resource type)


○ Apply safety algorithm to detect any deadlock
Deadlock Detection and Recovery (contd.)
● Process termination
○ Kill a process one at a time until we reach a safe state. This involves
computational overhead of running the deadlock safety algorithm
everytime we kill a process
○ Kill all the processes involved in a deadlock

● Resource Preemption
○ A process is chosen and preempted along with its corresponding
resources, till we reach a Safe state

You might also like