0% found this document useful (0 votes)
17 views9 pages

Adobe Scan 27-Nov-2024

The document discusses deadlocks in multi-programming environments, defining a deadlock as a situation where processes are unable to proceed because each is waiting for resources held by another. It outlines the necessary conditions for deadlocks to occur, methods for handling them including prevention, avoidance, and detection, and introduces the Banker's algorithm as a means of avoiding unsafe states. Additionally, it describes strategies for deadlock recovery, such as process termination and resource preemption.

Uploaded by

Nivya babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Adobe Scan 27-Nov-2024

The document discusses deadlocks in multi-programming environments, defining a deadlock as a situation where processes are unable to proceed because each is waiting for resources held by another. It outlines the necessary conditions for deadlocks to occur, methods for handling them including prevention, avoidance, and detection, and introduces the Banker's algorithm as a means of avoiding unsafe states. Additionally, it describes strategies for deadlock recovery, such as process termination and resource preemption.

Uploaded by

Nivya babu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

3

Deadlocks
3.1 Deadlock

In a
multi-programming environment, several processes may Compete for a finite
set of resources. A process requests resources, if the
are allotted to the process resources are available they
otherwise the process enters the wait state. It may
that waiting processes will never happen
again change state, because other
processes hold the resources they have waiting
deadlock. requested. This situation is called a
A set of process is in a
deadiock state if each process in the set is
event that can be caused by only waiting for an
another process in the set.
Definition : A deadlock is a situation in
resource are effectively preventing each otherwhich two processes sharing the same
from accessing the
in both
processes ceasing to function. resource, resulting
The resources may be l/o
devices (such as printers, tapedrives etc), memory
files, and CPU cycles. space,

[90]
Example 3.1
Process 1 requests resource A and receives it.

Process 2 requests resource B and receives it.


pending the release o
ProcesS 1requests resource B and is aueued up,
up, pending the release o A
Process 2 requests resource A and is queued as
releases a resource
Now neither process can proceed until the other process
shown in figure 3.1.

Resource k Process2 is
Process1 is
requesting
holding Resource
resource A

Process1
Process2

Process 2 is
Process 1i
requesting holding
resource B
Resource B Resource B

FIGURE 3.1

action to take. At this point the only


cannot know what
The operating system
the processes.
alternative is to abort (stop) one of

Deadlock Conditions
3.2 Necessary And Sufficient deadlock
simultaneously for a
four conditionsthat must hold
Coffman (1971) identified
to occur.
Mutual exclusion condition
1. at a time.
cannot be used by more than one process
A resource that (91]
2. Hold and wait condition
Processes already holding resources may request new resource In 3.3.
words, there must exist atleast one process that is holding a
resource alrean
allocated to ittwhile wating for additional resource that are currently
by other processes. being hee
3 No preemption condition
resource can be forcibly removed from a process holding it, 3.3.
can be released only by the explicit action of the process. resourcCs
Circular wait condition
Two or more processes form a circular chain where each process wak
resource that the next process in the chain holds. In other words there
exist a set (P. P.. , P) of waiting processes SUch that P, is
waiting for
resource that is held by P,.P, is waiting for a resOurce held by P, and
so on
finally P is waiting for a resource held by P
3.
3.3/Methods for Handling
Deadlocks
There are four methods for handling
deadlock problem.
1. The Ostrich Approach
Just ignore the deadlock
problem altogether.
2. Deadlock Prevention
Deadiocks can be prevented by ensuring that at
least one of the four conditions
(mentioned in Artical 6.10) fails to hold.
3 Deadiock Avoidance
Deadlock can be avoided by careful
resource scheduling,.
4
Deadlock Detection and Recovery
Detect deadlock and, when it
occurs, take steps to recover.
Let consider last three
us
methods
[92]
3.1 Deadlock Prevention conditions
least one of the four
at
Deadlocks can be prevented by ensuring that
(mentioned in Artical 6.10) fails to hold. these conditions.
occurrence of each of
Let us see
how can we prevent the

Exrclusion Condition
211 Elimination of Mutual Ithe resources sharable.
For
all sharable
This condition can be eliminated by making allow tha
would like to access a read-only file, then
example, f several processes are inherently
non-shareabie.
resources such as. printer
to happen. But some from non-sharable to
sharable.
cannot be changed
Therefore, these resources
cannot fulv eliminated. An effort should be made
Hence mutual exclusion condition
to prevent the mutual exclusion.

Elimination of Hold and Wait Condition


B.3.1.2
"hold and wait" condition.
There are two ways to eliminate
request and acquire all the requested resources before its
(1) Aprocess should
execution starts.

take the print out of a file, first request and aCquire the disk
For example, to
and printer.
should released all its resources before it requests for additional
(iü) A process
resources.

request the disk, get it, use


For example, to take the print out of a file, you first
it, use it and release it.
it and release it. Then you request the printer, get
Main problems with these approaches
need until the
(0) Many processes do not know how many resources they will
have started running.
Example 3.2

Provide a global numbering of all the resources, as shown below


1=Card reader
2= Printer

4= Tape drive

Now the rule is this : processes can request resOurces whenever they wart to,
all requests must be made in increasing order of numbers, A process may reque
first printer and then a tape drive (order :2. 4). but it may not request first a printe
and then a card reader (order: 2, 1).
This method ensure that circular wait condition do not held in the systerm. Theretore,
we nave Seen that by preventing one of these conditions, we can prevent the
deadlock.

3.3.2 Deadlock Avoidance


Deadlock can be avoided if certain information about processes is availabie n
advance of resource allocation. For every resource request, the system checkS
that allocating the resources, will the system be in a safe state or not?
(a) Safe State

Safe state is one where


It is not a deadlocked state.
There is some sequence by which all requests can be satisfied.
To avoid deadlocks, we try to make only those transitions that will take you

from one safe state to another.

(b) Unsafe State


System is said to be in unsafe state,if no safe sequence exists. A deadlock
state is a form of unsafe state as shown in figure 3.2. Therefore, avoiding the
system from entering in an unsafe state can avoid deadlock.
(95]
UNSAFE

DEADLOCK

SAFE

FIGURE 3.2

Example 3.3
Consider that there are total 11 tape drives and three processes. Maximum
requirement and currently allocated tape drives for each process at time t, is shown
in figure 3.3

Process Allocated Maximum Required


Po 5 11
P. 2
4
P 2
6
FIGURE 3.3
Hence Available tape drive = 11 - (5 +2 +2) =2
Safe State
The state of figure 6.6 is safe
allocation that allows all processesbecause there exists a sequence <P, P,,
to complete. Safe P> of
system has 2 tape drives and it state exists at this time because
allocates these tape drives to
completion of process P,, it (process P.) will release all four
process P,. So after
can allocate these tape tape drives. System
these tape drives to P drives to P, and after
completion of P,, system can allocate
[96]
UnsafeState

Maximum
requirement
shown in
and currently
allocated type drives for each process at firne
is figure 3.4
Process
Allocated Maximum Required
6
11
P 2 4

P2 2 6

FIGURE 3.4

Available tape drive = 11- (6+2+2)= 1


This is unsafe state.
Therefore, deadlock avoidance algorithm should be able to tell whether the system
is left in the safe state or not, after the request of particular process is granted. If the
algorithm finds that granting the request immediately will lead to an unsafe state,
then the process must be asked to wait.
One known algorithm that is used for deadlock avoidance is the Banker's algorithm,
which requires resOurce usage limit to be known in advance.

3.2.1 Banker's Algorithm


algorithm is so named because the process is analogous to that used by
Banker's
deciding ifa loan can be safely made. The algorithm check that if granting
abanker in
leads to an unsafe state, then the request is denied.
the request
C2, C3 and C4, each of whom has been granted a
Consider four customers C1,
units (e.g. 1 unit is 1 lakh rupees). The banker assumes
Certain number of credit
maximum credit immediately, so he has reserved
their
nat allcustomers willnot need
24 to service them as shown in figure 3.5
Oniy 10 units rather than
(97]
3.3.3.1 Deadlock Detection Algorithm (Resource - allocation
Adeadlock detection algorithm is a resource allocation
graaph.
allocation graph consists of The
a set of
vetices P =(P, P,, , P) of processes, denoted
by
(i) a set of vertices R= (R,, R, --, R) of resources
denoted oy circe,
(ii) Adirected edge P
’R from a process (P) to aresource
(R)
square,
has requested the resource R, dende
(v) Adirected edge R’P denotes that the resource Rhas
been al
the process P,.
We first mane the resource allocation graph
and note thatif there isa cir
among the processes, then it implies that a deadlock has Occurred
Example 3.4
Consider the following resource allocation graph as
shown in figure 3.8
R,

FIGURE 3.8
In this example,
Process P, is waiting for a resource R, held by
a resource held by P,. There P,. P, is watry
is a cycle in the
graph and thus the processes
deadiocked.
Deadlock Recovery
When a detection algorithm deternines that a deadiock exists, the systerm should
now be recovered from this state, There are two options for breaking a deadiock

(a) Process Termination


One way Is to abort all the dead locked processes, This technique is fast bu
a lot of the work done by all the deadlock processes will be lost
Another way is to abort one deadlock process at a time and check for

deadlock's presence again.


The advantage fo this method is that there is a possiblity that not al he
deadlocked processes will have to be aborted. The disadvantages of this
method is that this method involves more work as well as time bevau
detection algorithm will have to be invoked again after aborting each process
one by one.

(b) Resource Preemption


successively preempt
To eliminate deadlock using resource preemption, we
resources to other processes
some resources from processes and give these
issues pertaining to resource
untill the deadlock cycle is broken. There are three
preemption.
() Selectiog a Victim
resources and which process should become the target of
Which
process has completed almost 98 percent of its execution,
preemption? lfa
choice for preemption. Other factor can be the
then it should not be our
prOcess.
number of resources held by a

(ii) Rollback
process to some earlier safe
is rollback the preempted
Other possibility
execution from that point.
state and restart its
[101]

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy