Top Banner
DEEMED UNIVERSITY Seminar On Deadlock in Operating System By : Sri Bijay Kumar Giri Reg. No: 0305203065 MCA II nd Semester
18
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Deadlock

DEEMED UNIVERSITY

Seminar OnDeadlock in Operating System

By :

Sri Bijay Kumar Giri

Reg. No: 0305203065

MCA IInd Semester

Page 2: Deadlock

INTRODUCTION

Page 3: Deadlock

INTRODUCTION

Page 4: Deadlock

DEADLOCKDEADLOCK

Definition :

In a multiprogramming environment, several processes may complete for a finite number of resources . Process request recourses, if the resources aren’t available at that time, the process enters a wait state, because the resources they have requested are held by another waiting process. This situation is known as deadlock.

Page 5: Deadlock

EXAMPLE

In a bridge there are two openings. A car can move to the second opening of the bridge only if the car on the opposite side backs up otherwise starvation is possible.

Page 6: Deadlock

SYSTEM METHOD

1. REQUEST :-

2. USE :-

If the request can’t be granted immediately, then the requesting process must wait until it can acquire the resources.

The process can operate only the resources.

3. RELEASE :-

The process release the release the resources.

Page 7: Deadlock

DEADLOCK CHARACTERIZATION

It should be obvious that deadlocks are undesirable. In a deadlock, processes never finish executing and the system resources are tied up, preventing other job from ever starting.

NECESSARY CONDITIONS: - 1) MUTUAL

EXCLUSION 2) HOLD AND WAIT

3) NO

PREEMPTION 4) CIRCULAR WAIT

Page 8: Deadlock

RESOURCE – ALLOCATION GRAPH

Deadlocks can be described more precisely in terms of a directed graph called a system resource-allocation graph.

The set P, R, E : P={P1, P2, P3}R={R1,R2,R3,R4} E={P1->R1,P2->R3,R1->P2,R2->P2,R2->P1,R3->P3}

P1 P2 P3

R3

R2 R4

R1

Page 9: Deadlock

Continue………..

To illustrate this concept, let us return to the resource-allocation graph, which is given earlier.

P1->R1->P2->R3->P3->R2->P1

P2->R3->P3->R2->P2

Process P1, P2 and P3 are deadlocked. Process P2 is waiting for the resource R3, which is held by the process P3. Process on the other hand, is waiting for either process P1 or process P2 to release R1.

P1 P2 P3

R3

R2 R4

R1

Page 10: Deadlock

Continue………..

In this example, we also have a cycleP1->R1->P3->R2->P1

P1

P4

P3

P2

R1

R2

Page 11: Deadlock

METHOD OF HANDLING DEADLOCK

1. We can use a protocol to ensure that the system will never enter a deadlock state.2. We can allow the system to enter a deadlock state and then recover.3. We can ignore the problem al together and pretend that deadlock never occur in the system. This solution is one used by the most operating system, including UNIX.

Three different methods dealing with deadlock problem.

Page 12: Deadlock

DEADLOCK PREVENTION

1. MUTUAL EXCLUSION

2. HOLD AND WAIT

3. NO PREEMPTION

4. CIRCULAR WAIT

Page 13: Deadlock

DEADLOCK AVOIDANCE

1. SAFE STATE

DEADLOCKUNSAFE

SAFE

Maximum Needs Current NeedsP0 10 5P1 4 2P2 9 2

Page 14: Deadlock

RESOURCE-ALLOCATION GRAPH ALGORITHM

Continue………..

STEP 1 : In addition to request and assignment edges, we introduce a new type of head, called a claim edge.

STEP2 : A claim edge Pi - >Rj indicates that process Pi may request esource Rj at some time in future. This edge

resembles a request edge indirection, but is represented a dash line. STEP 3 : When Process Pi request Rj, the claim edge Pi -> Rj is

converted to a request edge.

STEP 4 : Similarly when a resource Rj is released by Pi, the assignment edge Rj -> Pi is reconverted to a claim edge, Pi -> Rj.

Page 15: Deadlock

Continue………..

STEP 5 : Suppose that process Pi request resource Rj. The request can be granted only if converting the request edge Pi to Rj is an assignment edge Rj -> Pi does not result in the formation of a cycle in resource-allocation graph. To illustrate this algorithm, we consider the resource allocation graph.

R1

P1 P2

R2

Page 16: Deadlock

Continue………..

BANKER’S ALGORITHM The deadlock avoidance algorithm that we describe next is

applicable to such a system, but is less efficient then the resource allocation graph scheme. This algorithm is commonly known as Banker’s Algorithm. The name was chosen because this algorithm could be used in a banking system to ensure that the bank never allocates its available case such that it can no longer satisfy the need of its customers.

When a new process enters the system, it must declare the maximum numbers of instances of each resource type that it may need. This number may not exceed than the total no of resources in the system. When a user request a set of resources, the system must determine whether the allocation of these resources will leave the system in a safe state. If it will, the resources are allocated; otherwise, the process must wait until some other process releases enough resources.

Page 17: Deadlock

RECOVERY FROM DEADLOCKThere are 2 options for breaking the deadlock.

1. PROCESS TERMINATION

a) Abort all deadlocked Process

b) Abort One Process at a Time until the deadlock cycle is eliminated

2. RESOURCE PREEMPTION a) Select a Victim

b) Roll Back

c) Starvation

Page 18: Deadlock