L6DeadLockf

Page 1

Chapter 7: Deadlocks

ef: Operating System Concepts with Java – 7 th Edition

Prof. Dr. Hanafy M. Ismail


Chapter 7: Deadlocks        

The Deadlock Problem System Model Deadlock Characterization Methods for Handling Deadlocks Deadlock Prevention Deadlock Avoidance Deadlock Detection Recovery from Deadlock

Ref: Operating System Concepts with Java – 7 th Edition

7.2

Prof. Dr. Hanafy M. Ismail


Chapter Objectives 

To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks To present a number of different methods for preventing or avoiding deadlocks in a computer system.

Ref: Operating System Concepts with Java – 7 th Edition

7.3

Prof. Dr. Hanafy M. Ismail


The Deadlock Problem 

A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set. Example  System has 2 disk drives.  P1 and P2 each hold one disk drive and each needs another one. Example  semaphores A and B, initialized to 1 P0 P1 wait (A); wait (B);

Ref: Operating System Concepts with Java – 7 th Edition

wait(B) wait(A)

7.4

Prof. Dr. Hanafy M. Ismail


Bridge Crossing Example

    

Traffic only in one direction. Each section of a bridge can be viewed as a resource. If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is possible.

Ref: Operating System Concepts with Java – 7 th Edition

7.5

Prof. Dr. Hanafy M. Ismail


System Model 

A system consists of a finite number of resources to be distributed among a number of competing processes. The resources are partitioned into several types, R1, R2, . . ., Rm , each consisting of some number of identical instances.  CPU cycles, memory space, I/O devices , and files are examples of resource types. Each resource type Ri has Wi instances. For example, the resource type printer may have five instances. Each process utilizes a resource as follows:  Request. If the resource cannot be granted immediately, the requesting process must wait until it can acquire the resource.  Use. The process can operate on the resource  Release. The process release the resource

Ref: Operating System Concepts with Java – 7 th Edition

7.6

Prof. Dr. Hanafy M. Ismail


Deadlock Characterization Deadlock can arise if four conditions hold simultaneously. 

 

Mutual exclusion: at least one resource must be held in a nonsharable mode; only one process at a time can use the resource. If another process requests that resource, it must be delayed until the resource has been released. Hold and wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No preemption: resources cannot be permitted; a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular wait: there exists a set {P0, P1, …, Pn } of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and Pn is waiting for a resource that is held by P0.

Ref: Operating System Concepts with Java – 7 th Edition

7.7

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph A set of vertices V and a set of edges E.

V is partitioned into two types:  P = {P1, P2, …, Pn}, the set consisting of all the processes in the system.  R = {R1, R2, …, Rm}, the set consisting of all resource types in the system. request edge – directed edge Pi → Rj

assignment edge – directed edge Rj → Pi

Ref: Operating System Concepts with Java – 7 th Edition

7.8

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph (Cont.) 

Process

Resource Type with 4 instances

Pi requests instance of Rj

Rj

Pi Rj

Pi is holding an instance of Rj

Pi Rj

Ref: Operating System Concepts with Java – 7 th Edition

7.9

Prof. Dr. Hanafy M. Ismail


Example of a Resource Allocation Graph

Ref: Operating System Concepts with Java – 7 th Edition

7.10

Prof. Dr. Hanafy M. Ismail


Resource Allocation Graph With A Deadlock

Ref: Operating System Concepts with Java – 7 th Edition

7.11

Prof. Dr. Hanafy M. Ismail


Graph With A Cycle But No Deadlock

Ref: Operating System Concepts with Java – 7 th Edition

7.12

Prof. Dr. Hanafy M. Ismail


Basic Facts  

If graph contains no cycles ⇒ no deadlock. If graph contains a cycle ⇒  if only one instance per resource type, then deadlock.  if several instances per resource type, possibility of deadlock.

Ref: Operating System Concepts with Java – 7 th Edition

7.13

Prof. Dr. Hanafy M. Ismail


Methods for Handling Deadlocks 

 

Ensure that the system will never enter a deadlock state; use either a deadlock prevention or deadlock avoidance scheme:  Deadlock prevention provides a set of methods for ensuring that at least one of the necessary conditions cannot hold.  Deadlock avoidance requires that the operating system be given in advance additional information concerning which resources a process will request and use during its lifetime. To decide whether the current request can be satisfied or must be delayed, the system must consider the resources currently available, the resources currently allocated to each process, and the future requests and releases of each process. Allow the system to enter a deadlock state and then recover; deadlock detection and recovery. Ignore the problem and pretend that deadlocks never occur in the system; used by most operating systems, including UNIX.

Ref: Operating System Concepts with Java – 7 th Edition

7.14

Prof. Dr. Hanafy M. Ismail


Deadlock Prevention By ensuring that at least one the four necessary conditions cannot hold, we can prevent deadlock:  

Mutual Exclusion – the condition must hold for nonsharable resources (e.g. printer). not required for sharable resources. Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources. Two protocols can be implemented:  Require process to request and be allocated all its resources before it begins execution, or  allow process to request resources only when the process has none. A process may request some resources and use them. Before it can request any more resources, it must release all the resources that is currently allocated.  Low resource utilization; starvation possible.

Ref: Operating System Concepts with Java – 7 th Edition

7.15

Prof. Dr. Hanafy M. Ismail


Deadlock Prevention (Cont.) 

No Preemption – to ensure that this condition does not hold, we can use the following protocol:  If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released.  Preempted resources are added to the list of resources for which the process is waiting.  Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. Circular Wait – one way to ensure that this condition never holds is to impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration.

Ref: Operating System Concepts with Java – 7 th Edition

7.16

Prof. Dr. Hanafy M. Ismail


Deadlock Prevention (Cont.)  

Let R = {R1, R2…., Rm} be the set of resource types. Assign a unique integer number to each resource type.  define a 1-1 function F: R  N  For example: F (tape drive) =1, F (disk drive) = 5, F (printer)= 12. Consider the following protocol to prevent deadlock:  Each process can request resources only in increasing order of enumeration:  a process can initially request any number of instances of a resource type Ri.  After that a process can request instances of resource type R iff j F(Rj) > F(Ri).  If several instances of the same resource type are needed, a single request of all of them must be issued.  Using this protocol the circular wait condition cannot hold: since process Pi+1 is holding resource Rj while requesting resource Rj+1, we must have F(Rj) < F(Rj+1), for all i. This means F(R0) < F(R1) < …< F(Rn) < F(R0). Which means F(R0) < F(R0) (impossible). Therefore there can be no circular wait.

Ref: Operating System Concepts with Java – 7 th Edition

7.17

Prof. Dr. Hanafy M. Ismail


Deadlock Avoidance Requires that the system has some additional a priori information available.  Simplest and most useful model requires that each process declare 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.  Resource-allocation state is defined by:  the number of available resources,  the number of allocated resources, and  the maximum demands of the processes.

Ref: Operating System Concepts with Java – 7 th Edition

7.18

Prof. Dr. Hanafy M. Ismail


Safe State   

When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in safe state if the system can allocate resources to each process (up to its maximum) in some order and still avoid deadlock. System is in safe state if there exists a safe sequence. A sequence of processes <P1, P2, …, Pn> is a safe sequence for the current allocation state, if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < i. That is:  If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.  When they have finished , Pi can obtain needed resources, execute, return allocated resources, and terminate.  When Pi terminates, Pi +1 can obtain its needed resources, and so on.

Ref: Operating System Concepts with Java – 7 th Edition

7.19

Prof. Dr. Hanafy M. Ismail


Basic Facts    

If a system is in safe state ⇒ no deadlocks. If a system is in unsafe state ⇒ possibility of deadlock. Avoidance ⇒ ensure that a system will never enter an unsafe state. A safe state is not a deadlock state; a deadlock state is an unsafe state. Not all unsafe states are deadlocks, however, an unsafe state may lead to a deadlock. As long as the state is safe, the operating system can avoid unsafe states.

Ref: Operating System Concepts with Java – 7 th Edition

7.20

Prof. Dr. Hanafy M. Ismail


Safe, Unsafe , Deadlock State

Ref: Operating System Concepts with Java – 7 th Edition

7.21

Prof. Dr. Hanafy M. Ismail


Avoidance algorithms  

Single instance of a resource type. Use a resource-allocation graph Multiple instances of a resource type. Use the banker’s algorithm

Ref: Operating System Concepts with Java – 7 th Edition

7.22

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph Scheme      

In addition to the request and assignment edges, there is a new type of edge called a claim edge. Claim edge Pi → Rj indicated that process Pi may request resource Rj; represented by a dashed line. Claim edge converts to request edge when a process requests a resource. Request edge converted to an assignment edge when the resource is allocated to the process. When a resource is released by a process, assignment edge reconverts to a claim edge. Resources must be claimed a priori in the system. That is, before process P starts executing, all its claim edges must already appear in the resource allocation graph. Allowing a new claim edge to a process only if all edges associated with the process are claim edges.

Ref: Operating System Concepts with Java – 7 th Edition

7.23

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph

Ref: Operating System Concepts with Java – 7 th Edition

7.24

Prof. Dr. Hanafy M. Ismail


Unsafe State In Resource-Allocation Graph

Ref: Operating System Concepts with Java – 7 th Edition

7.25

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph Algorithm  

 

Suppose that process Pi requests a resource Rj The request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph. If no cycle exists, then the allocation of the resource will leave the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe state. Therefore, the process Pi will have to wait for its request to be satisfied. In the example, suppose P2 requests R2. Although R2 is currently free, we cannot allocate it to P2, since this action will create a cycle in the graph (unsafe state); a deadlock occurs, if P1 requests R2 and P2 requests R1.

Ref: Operating System Concepts with Java – 7 th Edition

7.26

Prof. Dr. Hanafy M. Ismail


Banker’s Algorithm  

 

Multiple instances. Each process must a priori declare the maximum number of instances of each resource type that it may need. This number may not exceed the total number of resources in the system. When a process requests a resource it may have to wait if the allocation will leave the system in unsafe state. When a process gets all its resources it must return them in a finite amount of time.

Ref: Operating System Concepts with Java – 7 th Edition

7.27

Prof. Dr. Hanafy M. Ismail


Data Structures for the Banker’s Algorithm Let n = number of processes, and m = number of resources types.    

Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj. Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. Note. Let X and Y are two vectors , then, X ≤ Y iff X[i] ≤ Y[i] for all I = 1,2,3, …., n

Ref: Operating System Concepts with Java – 7 th Edition

7.28

Prof. Dr. Hanafy M. Ismail


Safety Algorithm: for finding whether or not a system is in safe state 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 0, 1, …, n- 1. 2. Find an i such that both: (a) Finish [i] = false (b) Needi ≤ Work If no such i exists, go to step 4. 3. Work = Work + Allocationi Finish[i] = true go to step 2. 4. If Finish [i] == true for all i, then the system is in a safe state.

Ref: Operating System Concepts with Java – 7 th Edition

7.29

Prof. Dr. Hanafy M. Ismail


Resource-Request Algorithm for Process Pi Request = request vector for process Pi. If Requesti [j] = k then process Pi wants k instances of resource type Rj. 1. If Requesti ≤ Needi go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim. If Requesti ≤ Available, go to step 3. Otherwise Pi must wait, since resources are not available. 3. Pretend to allocate requested resources to Pi by modifying the state as follows: Available = Available – Request; Allocationi = Allocationi + Requesti; Needi = Needi – Requesti; If safe ⇒ the resources are allocated to Pi. If unsafe ⇒ Pi must wait, and the old resourceallocation state is restored th 2.

Ref: Operating System Concepts with Java – 7

Edition

7.30

Prof. Dr. Hanafy M. Ismail


Example of Banker’s Algorithm 

5 processes P0 through P4;

3 resource types: A (10 instances), B (5 instances), and C (7 instances). Snapshot at time T0:

P0

Allocation ABC 010

Max ABC 753

P1

200

322

P2

302

902

P3

211

222

P4

002

433

Available ABC 332

Ref: Operating System Concepts with Java – 7 th Edition

7.31

Prof. Dr. Hanafy M. Ismail


Example (Cont.) 

The content of the matrix Need is defined to be Max – Allocation.

P0

Need ABC 743

P1

122

P2

600

P3

011

P4

431

The system is in a safe state since the sequence < P1, P3, P4, P2, P0> satisfies safety criteria.

Ref: Operating System Concepts with Java – 7 th Edition

7.32

Prof. Dr. Hanafy M. Ismail


Example: P1 Request (1,0,2) 

Check that Request ≤ Available (that is, (1,0,2) ≤ (3,3,2) ⇒ true. Allocation Need Available ABC ABC ABC P0 010 743 230 P1

302

020

P2

301

600

P3

211

011

P4

002

431

Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies safety requirement. Can request for (3,3,0) by P4 be granted?

Can request for (0,2,0) by P0 be granted?

Ref: Operating System Concepts with Java – 7 th Edition

7.33

Prof. Dr. Hanafy M. Ismail


Is Allocation (1 0 2) to P1 Safe?

ProcessAlloc ABC P0 0 1 0 P1 2 00 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 1 22 3 3 2 602 011 431

If P1 requests max resources, can complete Ref: Operating System Concepts with Java – 7 th Edition

7.34

Prof. Dr. Hanafy M. Ismail


Run Safety Test

ProcessAlloc ABC P0 0 1 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 020 2 3 0 602 011 431

If P1 requests max resources, can complete Ref: Operating System Concepts with Java – 7 th Edition

7.35

Prof. Dr. Hanafy M. Ismail


Allocate to P1, Then

Process Alloc ABC P0 0 1 0 P1 3 2 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Ref: Operating System Concepts with Java – 7 th Edition

Need Available ABC A B C 7 4 3 10 5 5 000 2 1 0 602 011 431

7.36

Prof. Dr. Hanafy M. Ismail


Release - P1 Finishes

Process Alloc ABC P0 0 1 0 P1 0 0 0 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 322 5 3 2 602 011 431

Now P3 can acquire max resources and release Ref: Operating System Concepts with Java – 7 th Edition

7.37

Prof. Dr. Hanafy M. Ismail


Release - P3 Finishes

Process Alloc ABC P0 0 1 0 P1 0 0 0 P2 3 0 0 P3 0 0 0 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 322 7 4 3 602 222 431

Now P4 can acquire max resources and release Ref: Operating System Concepts with Java – 7 th Edition

7.38

Prof. Dr. Hanafy M. Ismail


Release - P4 Finishes

Process Alloc ABC P0 0 1 0 P1 0 0 0 P2 3 0 0 P3 0 0 0 P4 0 0 0

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 322 7 4 5 602 222 433

Now P2 can acquire max resources and release Ref: Operating System Concepts with Java – 7 th Edition

7.39

Prof. Dr. Hanafy M. Ismail


Release - P2 Finishes

Process Alloc ABC P0 0 1 0 P1 0 0 0 P2 0 0 0 P3 0 0 0 P4 0 0 0

Max ABC 753 322 902 222 433

Need ABC 743 322 902 222 433

Available A B C 10 5 5 10 4 5

Now P0 can acquire max resources and release Ref: Operating System Concepts with Java – 7 th Edition

7.40

Prof. Dr. Hanafy M. Ismail


So P1 Allocation (1 0 2) Is Safe

Process Alloc ABC P0 0 1 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Ref: Operating System Concepts with Java – 7 th Edition

Need Available ABC A B C 7 4 3 10 5 5 020 2 3 0 602 011 431

7.41

Prof. Dr. Hanafy M. Ismail


Is allocation (0 2 0) to P0 Safe?

Process Alloc ABC P0 0 1 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 020 2 3 0 602 011 431

Try to Allocate 2 B to P0 Ref: Operating System Concepts with Java – 7 th Edition

7.42

Prof. Dr. Hanafy M. Ismail


Run Safety Test

Process Alloc ABC P0 0 3 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 2 3 10 5 5 020 2 1 0 602 011 431

No Processes may get max resources and release Ref: Operating System Concepts with Java – 7 th Edition

7.43

Prof. Dr. Hanafy M. Ismail


Avoid Unsafe State- Do Not give (0,2,0) to P0

Process Alloc ABC P0 0 3 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 2 3 10 5 5 020 2 1 0 602 011 431

Return to Safe State and do not allocate resource Ref: Operating System Concepts with Java – 7 th Edition

7.44

Prof. Dr. Hanafy M. Ismail


Suspend P0, Pending Request

Process Alloc ABC P0 0 1 0 P1 3 0 2 P2 3 0 0 P3 2 1 1 P4 0 0 2

Max ABC 753 322 902 222 433

Need Available ABC A B C 7 4 3 10 5 5 020 2 3 0 602 011 431

When enough resources become available, P0 can be woken Ref: Operating System Concepts with Java – 7 th Edition

7.45

Prof. Dr. Hanafy M. Ismail


Results 

P0’s request for 2 Bs cannot be granted because that would prevent any other process from completing if they need their maximum claim

Ref: Operating System Concepts with Java – 7 th Edition

7.46

Prof. Dr. Hanafy M. Ismail


Deadlock Detection   

Allow system to enter deadlock state Detection algorithm Recovery scheme

Ref: Operating System Concepts with Java – 7 th Edition

7.47

Prof. Dr. Hanafy M. Ismail


Single Instance of Each Resource Type 

If all resources have only a single instance, use wait-for graph (variant of resource allocation graph):  Nodes are processes.  Pi → Pj if Pi is waiting for Pj to release the resource that Pi needs. 

 

An edge Pi → Pj exists in a wait-for-graph iff the corresponding resource allocation graph contains two edges Pi → Rt and Rt → Pj . See next slide.

Periodically invoke an algorithm that searches for a cycle in the graph. If there is a cycle, there exists a deadlock. An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph.

Ref: Operating System Concepts with Java – 7 th Edition

7.48

Prof. Dr. Hanafy M. Ismail


Resource-Allocation Graph and Wait-for Graph

Resource-Allocation Graph

Corresponding wait-for graph

Ref: Operating System Concepts with Java – 7 th Edition

7.49

Prof. Dr. Hanafy M. Ismail


Several Instances of a Resource Type  

Available: A vector of length m indicates the number of available resources of each type. Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process. Request: An n x m matrix indicates the current request of each process. If Request [I ] [J ] = k, then process Pi is requesting k more instances of resource type. Rj.

Ref: Operating System Concepts with Java – 7 th Edition

7.50

Prof. Dr. Hanafy M. Ismail


Detection Algorithm 1. Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b)For i = 1,2, …, n, if Allocationi ≠ 0, then Finish[i] = false;otherwise, Finish[i] = true. 2. Find an index i such that both: (a)Finish[i] == false (b)Requesti ≤ Work If no such i exists, go to step 4.

Ref: Operating System Concepts with Java – 7 th Edition

7.51

Prof. Dr. Hanafy M. Ismail


Detection Algorithm (Cont.) 3. Work = Work + Allocationi Finish[i] = true go to step 2. 4. If Finish[i] == false, for some i, 1 ≤ i ≤ n, then the system is in deadlock state. Moreover, if Finish[i] == false, then Pi is deadlocked. Algorithm requires an order of O( m x n 2) operations to detect whether the system is in deadlocked state .

Ref: Operating System Concepts with Java – 7 th Edition

7.52

Prof. Dr. Hanafy M. Ismail


Example of Detection Algorithm 

Five processes P0 through P4; three resource types A (7 instances), B (2 instances), and C (6 instances). Snapshot at time T0: Allocation Request ABC ABC P0 0 1 0 000

P1

200

202

P2

303

000

P3

211

100

P4

002

002

Available ABC 000

Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i.

Ref: Operating System Concepts with Java – 7 th Edition

7.53

Prof. Dr. Hanafy M. Ismail


Example (Cont.) 

P2 requests an additional instance of type C. Request ABC P0 0 0 0

P1

201

P2

001

P3

100

P4

002

State of system?  Can reclaim resources held by process P0, but insufficient resources to fulfill other processes; requests.  Deadlock exists, consisting of processes P1, P2, P3, and P4.

Ref: Operating System Concepts with Java – 7 th Edition

7.54

Prof. Dr. Hanafy M. Ismail


Detection-Algorithm Usage 

 

When, and how often, to invoke depends on:  How often a deadlock is likely to occur?  How many processes will be affected by deadlock when it happened and need to be rolled back?  one for each disjoint cycle Deadlocks occur only when some process makes a request that cannot be granted immediately; this request may be the final request that completes a chain of waiting processes. In the extreme, we can invoke the deadlock detection algorithm each time a request for allocation cannot be granted. so we can also identify the process that caused the deadlock. The algorithm can be called at less frequent interval; for example, once per hour or when CPU utilization < 40%. If detection algorithm is invoked arbitrarily, there may be many cycles in the resource graph and so we would not be able to tell which of the many deadlocked processes “caused” the deadlock.

Ref: Operating System Concepts with Java – 7 th Edition

7.55

Prof. Dr. Hanafy M. Ismail


Recovery from Deadlock: Process Termination   

Abort all deadlocked processes. Abort one process at a time until the deadlock cycle is eliminated. In which order should we choose to abort?  Priority of the process.  How long process has computed, and how much longer to completion.  Resources the process has used.  Resources process needs to complete.  How many processes will need to be terminated.  Is process interactive or batch?

Ref: Operating System Concepts with Java – 7 th Edition

7.56

Prof. Dr. Hanafy M. Ismail


EX1 ď °

A system has four processes P1, P2, P3 and P4, and two resource types R1 and R2, each of which has two instances. Suppose further P1 is requesting an instance of R1 and allocated an instance of R2; P2 is allocated an instance of R1; P3 is requesting an instance of R2 and allocated an instance of R1; and P4 is allocated an instance of R2. Do the following two problems: (1) Draw the resource-allocation graph, and (2) Does this system have a deadlock?

Ref: Operating System Concepts with Java – 7 th Edition

7.57

Prof. Dr. Hanafy M. Ismail


EX2 ď °

Consider the following snapshot of a system with four resource types R1, R2, R3 and R4, and four processes A, B, C and D:

Ref: Operating System Concepts with Java – 7 th Edition

7.58

Prof. Dr. Hanafy M. Ismail


EX3 ď °

Consider the following snapshot of a system: Is this system in a safe state? Show your computation step-by-step;

Ref: Operating System Concepts with Java – 7 th Edition

7.59

Prof. Dr. Hanafy M. Ismail


End of Chapter 7

ef: Operating System Concepts with Java – 7 th Edition

Prof. Dr. Hanafy M. Ismail


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.