Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya.

Similar presentations


Presentation on theme: "CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya."— Presentation transcript:

1 CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya

2 Objective At the end of this presentation, you will know: What is a Deadlock? Preventing and Avoiding Deadlocks Detecting Deadlocks Recovery Schemes 2 CS 561 Deadlocks

3 What is a Deadlock? “ To get a job, you need experience. To gain experience you need a job ” Definition: The permanent blocking of a set of processes that compete for the system resources or communicate with each other. CS 561 Deadlocks 3

4 The Dining Philosopher’s Problem 5 Philosophers 5 Forks All Philosophers need a left fork and a right fork to eat. Deadlock : All philosophers reach for the left fork at the same time. CS 561 Deadlocks 4

5 System Model System has processes and resources Processes can – Request & wait for a resource – Use the resource – Release the resource after use. Deadlock: Each process is waiting for a resource being held by the other process. CS 561 Deadlocks 5 R1 R2 P1 P2 Hold Request

6 Deadlock Characterization Conditions for a deadlock to occur Mutual Exclusion : A resource can be used only by one process at a time. Hold & Wait : A process can retain holds on resources while it waits for other. No Preemption : No resource can be forcibly removed from a process holding it. Circular Wait : Process 1 is waiting for Process 2, Process 2 is waiting for Process 3 and Process 3 is waiting for process 1 All 4 of the above must happen at the same time for deadlock to occur. CS 561 Deadlocks 6

7 Resource Allocation graphs Depicts the state of the system of resources and processes Process Resource and instances Request from process to resource Allocated instance CS 561 Deadlocks 7 PiPi RiRi PiPi RiRi PiPi RiRi

8 Resource Allocation Graph with cycle and deadlock Resource Allocation Graph with cycle and no deadlock CS 561 Deadlocks 8 P1P1 P2P2 P3P3 P3P3 P3P3 P2P2 P1P1 R1R1 R2R2 R4R4 R3R3 R2R2 R1R1

9 Handling Deadlocks Ostrich Algorithm – Pretend there is no problem Deadlock Prevention – Stop the four conditions from happening Deadlock Avoidance – Allow deadlock conditions – Calculate safe and unsafe states Deadlock Detection – Allow the deadlock to happen – Recover from the deadlock CS 561 Deadlocks 9 Stop Deadlock from happening

10 Deadlock Prevention Mutual Exclusion – Disallow mutual exclusion for sharable resources Hold & Wait – Process requests all requires resources at one time. – Low resource utilization & Starvation No Preemption – Process must let go of all holds before making a new request Circular Wait – Define linear ordering on resources CS 561 Deadlocks 10

11 State of the system is calculated – Unsafe State : Deadlock may occur. – Safe State : Ample resource instances exist. – Denial of resource allocation happens if request causes unsafe state CS 561 Deadlocks 11 SAFE DEADLOCK UNSAFE O.S. can avoid deadlock. Only with luck will processes avoid deadlock. Deadlock Avoidance

12 Deadlock Avoidance contd. Assume a simple model: – 3 Processes & 12 Magnetic tape drives. – The current state is as follows: CS 561 Deadlocks 12 The safe order of execution is The system enters an unsafe state when p2 requests and is allocated another tape. A safety algorithm is used to detect the safe state by calculating the needs of the processes and the amount of resource allocated.

13 When resource has only one instance: – Use resource allocation graph to detect cycles When resource has multiple instances: – Cycles do not mean deadlocks – Use Banker’s algorithm All processes must return resources within a finite amount of time. Processes may have to wait for allocation CS 561 Deadlocks 13 Deadlock Avoidance contd.

14 Deadlock Detection Let the deadlock happen Detect deadlock – For single instance resource : Detect cycle with Resource Allocation Graph – For multiple instance resource keep track of: Available resources Allocated resources Number of requests made Recover from deadlock CS 561 Deadlocks 14

15 Recovery Techniques Abort all deadlocked processes. Rollback deadlocked process to previous checkpoint and restart. Abort deadlocked process successively till deadlock disappears. Preempt deadlocked resources till deadlock disappears CS 561 Deadlocks 15

16 Criterion for aborting and preempting processes Least consumption of processor time Least amount of output produced Most time remaining Least total allocated resources Lowest priority CS 561 Deadlocks 16 Recovery Techniques contd.

17 Wrapping up… There are strengths and weaknesses to all approaches Use a different strategy in different situations depending on: – Memory – Internal resources – Process resources CS 561 Deadlocks 17

18 THANK YOU CS 561 Deadlocks 18


Download ppt "CS 450 OPERATING SYSTEMS DEADLOCKS Manju Muralidharan Priya."

Similar presentations


Ads by Google