1 Advanced Operating Systems - Spring 2009 Lecture 9 – February 9, 2009 Dan C. Marinescu Office: HEC 439 B. Office.

Slides:



Advertisements
Similar presentations
Chapter 7: Deadlocks.
Advertisements

Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 12: Deadlocks (Chapter 7)
Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Silberschatz, Galvin and Gagne ©2007 Deadlocks  (How to Detect Them and Avoid Them) A:
Deadlocks CS 3100 Deadlocks1. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held by another.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 8: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks.
1 Wednesday, June 28, 2006 Command, n.: Statement presented by a human and accepted by a computer in such a manner as to make the human feel that he is.
Chapter 7. Deadlocks.
Chapter 7: Deadlocks. 7.2 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks.
1 Chapter 7: Deadlock. 2 The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 8: Deadlocks System Model Deadlock Characterization
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
02/19/2008CSCI 315 Operating Systems Design1 Deadlock Notice: The slides for this lecture have been largely based on those accompanying the textbook Operating.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Deadlocks Gordon College Stephen Brinton. Deadlock Overview The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks.
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 7: Deadlock Dr. Mohamed Hefeeda.
What we will cover…  The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Objectives Understand the Deadlock.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Deadlocks.
Chapter 7: Deadlocks Adapted to COP4610 by Robert van Engelen.
System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention, Avoidance, and Detection Recovering from Deadlock Combined Approach.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks Modified.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7 Deadlocks. 7.2 Modified By Dr. Khaled Wassif Operating System Concepts – 7 th Edition Silberschatz, Galvin and Gagne ©2005 Chapter 7: Deadlocks.
Cosc 4740 Chapter 6, Part 4 Deadlocks. The Deadlock Problem A set of blocked processes each holding a resource and waiting to acquire a resource held.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-6 Deadlocks Department of Computer Science and Software Engineering.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 AE4B33OSS Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
CHAPTER 8: DEADLOCKS System Model Deadlock Characterization
 The Deadlock Problem  System Model  Deadlock Characterization  Methods for Handling Deadlocks  Deadlock Prevention  Deadlock Avoidance  Deadlock.
Dr. Kalpakis CMSC 421, Operating Systems Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks System Model Deadlock Characterization Methods.
Lecture 12 Handling Deadlock – Prevention, avoidance and detection.
Mi-Jung Choi Dept. of Computer and Science Silberschatz, Galvin and Gagne ©2006 Operating System Principles Chapter 7: Deadlocks.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 7: Deadlocks.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Lecture 7 Operating Systems.
Chapter 8 Deadlocks. Objective System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection.
Chapter 7: Deadlocks. 7.2CSCI 380 – Operating Systems Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization Methods for Handling.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock Characterization.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
CS307 Operating Systems Deadlocks Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
國立台灣大學 資訊工程學系 Chapter 7: Deadlocks. 資工系網媒所 NEWS 實驗室 Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes.
Chap 7 Deadlocks. Chapter Objectives To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 6 Deadlocks Slide 1 Chapter 6 Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Deadlocks Introduction to Operating Systems: Module 7.
7.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter Objectives To develop a description of deadlocks, which.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 7: Deadlocks The Deadlock Problem System Model Deadlock.
7.1 CSE Department MAITSandeep Tayal 7: Deadlocks System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Chapter 7: Deadlocks. 7.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts - 7 th Edition, Feb 14, 2005 Chapter 7: Deadlocks The Deadlock.
CSE Operating System Principles Deadlocks. CSE – Operating System Principles2 Overview System Model Deadlock Characterization Methods for.
Deadlock. Examples You can't get a job without experience; you can't get experience without a job. A set of blocked processes each holding a resource.
Chapter 7: Deadlocks. The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Chapter 7: Deadlocks.
Deadlock B.Ramamurthy CSE421 1/11/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 2/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 4/23/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 5/1/2019 B.Ramamurthy.
CSCI 315 Operating Systems Design
Deadlock B.Ramamurthy CSE421 8/28/2019 B.Ramamurthy.
Deadlock B.Ramamurthy CSE421 9/3/2019 B.Ramamurthy.
Presentation transcript:

1 Advanced Operating Systems - Spring 2009 Lecture 9 – February 9, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours: M, Wd 3 – 4:30 PM. TA: Chen Yu Office: HEC 354. Office hours: M, Wd 1.00 – 3:00 PM.

2 Last, Current, Next Lecture Last time: Atomic transactions Today Three-way handshake Deadlocks Next time: Deadlocks

3 Three-way handshake TCP uses a three-way handshake between a client and a server process: Passive open: The server must first bind to a port to open it up for connections. A client may initiate an active open to this port. The three-way handshake: 1. The client sends a SYN to the server for an active open. 2. The server replies with a SYN-ACK. 3. The client sends an ACK (usually called SYN-ACK-ACK) back to the server.

4 Tri-way handshake example The client sends a Synchronization packet to initiate a connection. A SYN packet has a Sequence Number (SN). (SN is 32-bit field in TCP segment header), e.g., SN=x. The server receives the packet, records the SN and replies with an Acknowledgment and Synchronization (SYN-ACK). The Acknowledgment Number (AN) is a 32-bit field in TCP segment header. It contains the next sequence number that this host is expecting to receive (x + 1). The server also initiates a return session. This includes a TCP segment with its own initial SN, e.g., SN=y. The client responds with the next SN= (x+1) and an AN=y + 1 (the SN of the server + 1).

5

6 Deadlocks System Model Deadlock Characterization Safe State Resource Allocation Graph Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock

7 Deadlocks Happen quite often in real life and the proposed solutions are not always logical: “ When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone.” a pearl from Kansas legislation. Deadlock jury. Deadlock legislative body.

8

9 Deadlocks in computer systems Deadlocks  prevent sets of concurrent processes from completing their tasks. How does a deadlock occur  a set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. Example semaphores A and B, initialized to 1 P 0 P 1 wait (A);wait(B) wait (B);wait(A) Aim  prevent or avoid deadlocks

10 Example of a deadlock Traffic only in one direction. Solution  one car backs up (preempt resources and rollback). Several cars may have to be backed up. Starvation is possible.

11 System model Resource types R 1, R 2,..., R m (CPU cycles, memory space, I/O devices) Each resource type R i has W i instances. Resource access model: request use release

12 Simultaneous conditions for deadlock Mutual exclusion: only one process at a time can use a resource. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: a resource can be released only voluntarily by the process holding it (presumably after that process has finished). Circular wait: there exists a set {P 0, P 1, …, P 0 } of waiting processes such that P 0 is waiting for a resource that is held by P 1, P 1 is waiting for a resource that is held by P 2, …, P n–1 is waiting for a resource that is held by P n, and P 0 is waiting for a resource that is held by P 0.

13 Safe state Safe state  there exists a sequence of ALL the processes is the systems such that for each P i, the resources that P i can still request can be satisfied by currently available resources + resources held by all the P j, with j < i (ordering of processes). This implies: If P i resource needs are not immediately available  then P i can wait until all P j have finished. When P j finishes  P i can obtain needed resources, execute, return allocated resources, and terminate. When P i terminates  P i +1 can obtain its needed resources, and so on. When a process requests an available resource, the system must decide if immediate allocation leaves the system in a safe state.

14 Safe state and deadlocks Safe state  no deadlocks. Unsafe state  possibility of deadlock.

15 Resource allocation graph (V,E) Directed bipartite graph: two types of nodes in V: P = {P 1, P 2, …, P n }  processes. R = {R 1, R 2, …, R m }  resource types. request edge – directed edge P 1  R j assignment edge – directed edge R j  P i

16 Resource allocation graph (cont’d) Process Resource Type with 4 instances P i requests an instance of R j P i is holds an instance of R j PiPi PiPi RjRj RjRj

17 Cycles in a resource allocation graph No cycles  no deadlock. A cycle  only one instance per resource type  deadlock. multiple instances of each resource type  possibility of deadlock.

18 Resource allocation graph with a deadlock

19 Graph with a cycle but no deadlock

20 Alternatives Deadlock prevention and avoidance  ensure that the system will never enter a deadlock state. Allow the system to enter a deadlock state  then recover. Ignore the problem  used by most operating systems, including UNIX.

21 Deadlock prevention vs. deadlock avoidance Deadlock Prevention: Ensure that at least one of the necessary conditions for deadlock can never hold. Constraining how requests for resources can be made and how they are handled (system design). Deadlock Avoidance: The system requires additional apriori information regarding the overall potential use of each resource for each process. The system dynamically considers every request and decides whether it is safe to grant it at this point, Allows more concurrency. Similar to the difference between a traffic light and a police officer directing traffic.

22 Deadlock prevention  restrict how requests can be made. Mutual Exclusion  not required for sharable resources; must hold for nonsharable resources. Hold and Wait  guarantee that whenever a process requests a resource, it does not hold any other resources. A process must request and be allocated all resources before it begins execution, or allow a process to request resources only when it has none. Low resource utilization; starvation possible.

23 Deadlock prevention (Cont.) No Preemption If a process holding some resources requests another resource that cannot be immediately allocated to it, then release all resources currently held by the process. Preempted resources added to the list of resources for which the process is waiting. Process restarted only when it can regain its old resources, as well as the new ones that it is requesting. Circular Wait  impose a total ordering of all resource types, and each process requests resources in an increasing order of enumeration.

24 Deadlock avoidance Requires that the system has some additional a priori information available Resource-allocation state  defined by the number of available and allocated resources, and the maximum demands of the processes. Each process declares the maximum number of resources of each type that it may need. The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition..

25 Avoidance algorithms Single instance of a resource type  use a resource- allocation graph Multiple instances of a resource type  use the banker’s algorithm

26 Resource allocation graph scheme Assignment edge  directed edge R j  P i Request edge  directed edge P i  R j Claim edge P i  R j (dashed line) P j may request resource. Dynamics: A process requests a resource: Claim edge  Request edge A resource is allocated to the process: Request edge  Assignment edge. A resource is released: Assignment edge  Claim edge. Resources must be claimed a priori in the system.

27 Resource allocation graph

28 Unsafe state in a resource allocation graph

29 Resource allocation graph algorithm Assume process P i requests a resource R j The request can be granted  if and only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph

30 Banker’s algorithm Multiple resource instances. Each process must a priori claim maximum use. When a process requests a resource it may have to wait gets all its resources it must return them in a finite amount of time.

31 Data structures for banker’s algorithm Available: Vector of length m: Available [j] = k  there are k instances of resource type R j available. Max: n x m matrix: Max [i,j] = k  P i may request at most k instances of resource type R j. Allocation: n x m matrix: Allocation[i,j] = k  P i is currently allocated k instances of R j. Need: n x m matrix: Need[i,j] = k  P i may need k more instances of R j to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. n  # of processes; m  # of resources types.

32 Safety algorithm 1. Work and Finish are vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 0, 1, …, n Find i such that: (a) Finish [i] = false (b) Need i  Work If no such i exists, go to step Work i = Work i + Allocation i Finish[i] = true go to step 2. 4.If Finish [i] == true for all i, then the system is in a safe state.

33 Resource request algorithm for process P i If request vector Request i [j] = k then P i wants k instances of resource type j (R j. ) 1.If Request i  Need i go to step 2. Otherwise  error (process has exceeded its maximum claim). 2.If Request i  Available, go to step 3. Otherwise  P i must wait (resources are not available). 3.Pretend to allocate requested resources to P i by modifying the state as follows: Available = Available – Request; Allocation i = Allocation i + Request i ; Need i = Need i – Request i ; l If safe  the resources are allocated to P i l If unsafe  P i must wait, and the old resource- allocation state is restored

34 Example 5 processes P 0 through P 4 ; 3 resource types: A (10 instances), B (5instances), and C (7 instances). Snapshot at time T 0 : AllocationMaxAvailable A B CA B C A B C P P P P P

35 Example (cont’d) The content of the matrix Need is defined to be Max – Allocation. Need A B C P P P P P The system is in a safe state since the sequence satisfies safety criteria.

36 Example: P 1 Request (1,0,2) Check that Request  Available (that is, (1,0,2)  (3,3,2)  true. AllocationNeedAvailable A B CA B CA B C P P P P P Executing safety algorithm shows that sequence satisfies safety requirement. Can request for (3,3,0) by P 4 be granted? Can request for (0,2,0) by P 0 be granted?