deadlocks by wani zahoor
TRANSCRIPT
Baba Ghulam Shah Badshah University- Rajouri
Department of Information Technology
Topic : DEAD LOCKS IN OPERATING SYSTEM
Presented By: Wani Zahoor 1-MIT-2015
DEADLOCKS IN
OPERATING SYSTEM“Cris
es and Deadlocks
when they occu
r have at
least this
advantage,
that they force
us to
think.”- Jawaharla
l Nehru
(1889 - 1964)
Indian
political le
ader
DEADLOCK - Definition
When a process requests the resources, the resources are not available at that time, so the process enters into the waiting state. The requesting resources are held by another waiting process, both are in waiting state, this situation is said to be a. .. “Deadlock”
A set of blocked processes each holding a resource and waiting to acquire a resource held by another
process in the set.
o Example Process-1 requests the printer, gets itProcess-2 requests the tape unit, gets it Process-1 andProcess-1 requests the tape unit, waits Process-2Process-2 requests the printer, waits Deadlocked!
WHAT ARE DEADLOCKS???
1. Mutual Exclusion Condition
2. Hold & Wait Condition
3. No Preemption Condition
4. Circular Wait Condition
FOUR CONDITIONS FOR DEADLOCKS?
DEADLOCK MODELING ?
Modeled with directed graphs
Resource Allocation Graph
If we have a resource allocation system with only one inatance of each process, a variant of the resource allocation graph can be used for deadlock avoidance.
R1 R2
R3 R4
P1 P2P3
Resource Allocation Graph
CIRCLES represents processes
SQUARE represents classes of identical resources
SMALL SQUARES DRAWN INSIDE LARGE SQUARES Indicate separate identical resources of each class
RESOURCE ALLOCATION GRAPH ?
If the Resource Allocation graph contains no cycles then there is no deadlock in the system at that instance.
If there is a Cycle
o If there is only one instance per resource type than there is a Deadlock
o If there is more than once instance for some resource type than there may or may not be a Deadlock
RESOURCE ALLOCATION GRAPH ?
EXAMPLE OF A RESOURCE ALLOCATION GRAPH
• Four major Areas of Interest in Deadlocks:
Deadlock Prevention
Deadlock Avoidance
Deadlock Detection
Deadlock Recovery
HOW TO HANDLE DEADLOCKS ?
• Prevention eliminates one of the four Conditions:
1. Elimination Of Mutual Exclusion
2. Elimination Of Hold & Wait Condition
3. Elimination Of No Preemption Condition
4. Elimination Of Circular Wait Condition
DEADLOCK PREVENTION ?
• Maximum requirements of each resource must be stated in advance by each process.
• Two Approaches
• Two Algorithmso Resource Allocation Algorithmso The Banker’s Algorithm
DEADLOCK AVOIDANCE ?
Banker's Algorithm When a request is made, check to see if after the request is satisfied, there is a (atleast one!) sequence of moves that can satisfy all the requests i,e. the new state is safe.
If so, satisfy the request, else make the request wait. ..
• Determines if deadlock has occurred• Identifies those processes & resources involved in the deadlock• Algorithms can incur significant runtime overhead
DEADLOCK DETECTION ???
Detection mechanism of Deadlocks for single instance of resource type is different. We can detect the dead locks using wait for graph for single instance resource type and detect using detection algorithm for multiple instances of resource type.
1. SINGLE INSTANCE OF RESOURCE TYPE : Single instance of resource type means, the system consisting of only one resource for one type. We can detect this type of deadlocks with the help of wait for graph.
DEADLOCK DETECTION MECHANISMS
2. SEVERAL INSTANCE OF RESOURCE TYPE :
The wait for graph is not applicable to several instance of resource type. So we need another method for this type, that is “deadlock detection algorithm”. This algorithm looks like ‘Banker’s algorithm” and it employees several data structures that are similar to those used in the …
Banker’s Algorithm.
• Process Terminationo Abort all deadlocked processes.o Abort one process at a time until the deadlock cycle is eliminated.
• Resource Preemptiono Selecting a victimo Rollbacko Starvation
RECOVERY FROM DEADLOCKS ?
PROCESS TERMINATION “Process Termination” it is one method to recover from
deadlock. We uses 2 methods for process termination, these are:
a)ABORT ALL DEADLOCKED PROCESS : It means release all the processes in the deadlocked state, and start the allocation from the starting point. It is a great expensive method.
b)ABORT ONE BY ONE PROCESS UNTIL THE DEADLOCK CYCLE IS ELIMINATED : In this method first abort the one of the processes in the deadlocked state, and allocated the resources to some other process in the deadlock state then check whether the deadlock breaked or not. If no, abort the another process from the deadlock state. Continue this process until we recover from deadlock. This method is also expensive but compare with first one it is better.
RESOURCE PREEMPTION To eliminate deadlocks using resource preemption, preempt
some resourcesfrom processes and give these resources to other processes until the deadlock cycle is broken.There are 3 methods to eliminate the deadlocks using resource preemption.These are :a)SELECTING A VICTIM : Select a victim resource from the
deadlock state, and preempt that one.b)ROLLBACK : If a resource from a process is preempted,
what should be done with that process. The process must be roll backed to some safe state and restart it from that state.
c)STARVATION : It must be guaranteed that resource will not always be preempted from the same process to avoid starvation problem.
Thank You…
Have a Nice Day !!!