deadlocks by wani zahoor

23
Baba Ghulam Shah Badshah University- Rajouri Department of Information Technology Topic : DEAD LOCKS IN OPERATING SYSTEM Presented By: Wani Zahoor 1-MIT-2015

Upload: wani-zahoor

Post on 25-Jan-2017

261 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Deadlocks by wani zahoor

Baba Ghulam Shah Badshah University- Rajouri

Department of Information Technology

Topic : DEAD LOCKS IN OPERATING SYSTEM

Presented By: Wani Zahoor 1-MIT-2015

Page 2: Deadlocks by wani zahoor

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

Page 3: Deadlocks by wani zahoor
Page 4: Deadlocks by wani zahoor

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”

Page 5: Deadlocks by wani zahoor

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???

Page 6: Deadlocks by wani zahoor

1. Mutual Exclusion Condition

2. Hold & Wait Condition

3. No Preemption Condition

4. Circular Wait Condition

FOUR CONDITIONS FOR DEADLOCKS?

Page 7: Deadlocks by wani zahoor

DEADLOCK MODELING ?

Modeled with directed graphs

Page 8: Deadlocks by wani zahoor

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.

Page 9: Deadlocks by wani zahoor

R1 R2

R3 R4

P1 P2P3

Resource Allocation Graph

Page 10: Deadlocks by wani zahoor

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 ?

Page 11: Deadlocks by wani zahoor

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 ?

Page 12: Deadlocks by wani zahoor

EXAMPLE OF A RESOURCE ALLOCATION GRAPH

Page 13: Deadlocks by wani zahoor

• Four major Areas of Interest in Deadlocks:

Deadlock Prevention

Deadlock Avoidance

Deadlock Detection

Deadlock Recovery

HOW TO HANDLE DEADLOCKS ?

Page 14: Deadlocks by wani zahoor

• 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 ?

Page 15: Deadlocks by wani zahoor

• 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 ?

Page 16: Deadlocks by wani zahoor

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. ..

Page 17: Deadlocks by wani zahoor

• Determines if deadlock has occurred• Identifies those processes & resources involved in the deadlock• Algorithms can incur significant runtime overhead

DEADLOCK DETECTION ???

Page 18: Deadlocks by wani zahoor

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

Page 19: Deadlocks by wani zahoor

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.

Page 20: Deadlocks by wani zahoor

• 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 ?

Page 21: Deadlocks by wani zahoor

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.

Page 22: Deadlocks by wani zahoor

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.

Page 23: Deadlocks by wani zahoor

Thank You…

Have a Nice Day !!!