Eminar On: Deadlock in Operating System

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 18

Seminar On

Deadlock in Operating System


Prepared By :
INTRODUCTION
INTRODUCTION
DEADLOCK
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.
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.
SYSTEM METHOD
1. REQUEST :-
If the request can’t be granted immediately, then
the requesting process must wait until it can
acquire the resources.

2. USE :-
The process can operate only the resources.

3. RELEASE :-
The process release the release the resources.
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
RESOURCE – ALLOCATION GRAPH
Deadlocks can be described more precisely in terms of a directed
graph called a system resource-allocation graph.
R1 R3

P1 P2 P3

R2 R4

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}
Continue………..
To illustrate this concept, let us return to the resource-allocation
graph, which is given earlier.
R1 R3

P1 P2 P3

R2
R4

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

P2

R1

P1 P3
R2

P4

In this example, we also have a cycle


P1->R1->P3->R2->P1
METHOD OF HANDLING DEADLOCK
Three different methods dealing with deadlock problem.
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.
DEADLOCK PREVENTION

1. MUTUAL EXCLUSION

2. HOLD AND WAIT

3. NO PREEMPTION

4. CIRCULAR WAIT
DEADLOCK AVOIDANCE

1. SAFE STATE

UNSAFE
DEADLOCK

SAFE

Maximum Needs Current Needs


P0 10 5
P1 4 2
P2 9 2
Continue………..

RESOURCE-ALLOCATION GRAPH ALGORITHM


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.
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
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.
RECOVERY FROM DEADLOCK
There 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

You might also like