Académique Documents
Professionnel Documents
Culture Documents
A
SEMINAR REPORT
Submitted by
Mahipal Singh
(Roll No:-1305020116)
In partial fulfilment for the award of the degree
Of
MASTER OF COMPUTER APPLICATION
2015
DEPARTMENT OF
INFORMATION TECHNOLOGY
`
CERTIFICATE
This is to certify that the Seminar titled Deadlock was prepared and
presented by Mahipal Singh Roll No. 1305020116 of V Semester in partial
fulfilment of requirement for the award of Degree of Masters in Computer
Application under Sikkim Manipal University Directorate of Distance
Education
SEMINAR GUIDE
Acknowledgement
The enduring of the work is the cumulative sequence of extensive guidance & arduous work.
We wish to acknowledge and express our personal gratitude to all those without whom this
work could not have been reality. I am greatly indebted to Mr. Navin Purohit & Mr. Richard
Kumar gave me an opportunity to work in such a professional & inspiring environment. I feel
very delighted to get this rare opportunity to show my profound senses of reverence &
indebtedness to our esteemed teachers to Mr.Navin Purohit & Mr. Richard Kumar for their
keen & sustained interest, valuable advice. For this type of consideration I behold there in a
special manner & no words can fully convey our regards for them. I want to acknowledge all
those who have directly or indirectly helped & cooperated in accomplishing this seminar.
Abstract
Deadlock has been widely studied in many fields of computer science, notably in
communications, database, and operating systems. Perhaps because (at least one state called)
deadlock is tractable, there exists extensive literature on the subject.
Deadlock was apparently decisively defined over thirty years ago, with its
characteristics and handlers. Yet, much of the literature remains inconsistent in its treatment
of this anomaly.
A more precise definition is clearly needed to distinguish between the different states
that are termed deadlock. A classification of dead states is required to distinguish the causes
and appropriate handlers for each.
Table of Contents
CHAPTER 1
INTRODUCTION
CHAPTER 2
CHAPTER 3
CHAPTER 4
CHAPTER 5
CHAPTER 6
REFERENCES
DEADLOCK CHARACTERIZATION
RESOURCE ALLOCATION GRAPH
METHODS OF HANDLING DEADLOCK
RECOVERY FROM DEADLOCK
CONCLUSION
1: INTRODUCTION
Dead-lock is a condition that may involve two or more processes in a state such that each is
waiting for release of a resource currently held by some other process.
Examples:
A person going down a ladder while another person is climbing up the ladder.
A process must request a resource before using it and must release the resource after using it.
A process may request as many resources as it requires to carry out its designated task.
Obviously, the number of resources requested may not exceed the total number of resources
available in the system. In other words, a process cannot request three printers if the system
has only two.
Under the normal mode of operation, a process may utilize a resource in only the following
sequence:
1. Request- If the request cannot be granted immediately (for example, if the resource is
being used by another process), then the requesting process must wait until it can acquire the
resource.
2. Use-The process can operate on the resource (for example, if the resource is a printer,
the process can print on the printer).
3. Release-The process releases the resource.
2. DEADLOCK CHARACTERIZATION
A deadlock situation can arise if the following four conditions hold simultaneously in a
system:
1. Mutual exclusion- At least one resource must be held in a non-sharable mode; that is,
only one process at a time can use the resource.
2. Hold and wait-A process must be holding at least one resource and waiting to acquire
additional resources that are currently being held by other processes.
3. No pre-emption-Resources cannot be pre-empted; that is, a resource can be released
only voluntarily by the process holding it, after that process has completed its task.
4.Circular wait- A set { P0 , P1, ... , Pn } of waiting processes must exist such that Po is
waiting for a resource held by P1, P1 is waiting for a resource held by P2, ... , Pn-1 is waiting
for a resource held by Pn and P0 is waiting for a resource held by Pn.
set consisting of all the active processes in the system, and R == {R1 , R2 , ... , Rm} the set
consisting of all resource types in the system.
Without a deadlock
with a deadlock
10
Prevention-We can use a protocol to prevent or avoid deadlocks, ensuring that the system will
never enter a deadlocked state.
Detection-We can allow the system to enter a deadlocked state, detect it, and recover.
Avoidance-We can ignore the problem altogether and pretend that deadlocks never occur in
the system.
Deadlock prevention
1. Mutual Exclusion not required for sharable resources; must hold for non-sharable
resources
2. Hold and Wait must guarantee that whenever a process requests a resource, it does
not hold any other resources
3. No Pre-emption
4. Circular Wait impose a total ordering of all resource types, and require that each process
Requests resources in an increasing order of enumeration.
Deadlock avoidance
Simplest and most useful model requires that each process declare the maximum number of
resources of each type that it may need
11
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 there exists a sequence <P1, P2, , Pn> of ALL the processes
is the systems such that for each P i, 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 Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and
terminate
Customer
Used
Max need
Current need
5
12
Available units = 2
(Safe state)
Customer
Used
Max need
Current need
Available units = 1
(Unsafe state)
One process should releases resources at that time
13
2. Unsafe state
14
3. bankers algorithm
This algorithm can be used in a banking system to ensure that the bank never allocates its
available cash such that it can no longer satisfy the needs of its customers.
Multiple instances
When a process requests a resource it may have to wait
When a process gets all its resources it must return them in a finite amount of time
Bankers algorithm uses two tests whenever a process makes a request:
Feasibility test: a request is feasible if no. of requested units is less then no. of free units at that time.
Safety test: a request is safe if after granting the request, there exist at least one sequence of resource
allocation.
Max
Available
16
ABC
ABC
ABC
P0
010
753
332
P1
200
322
P2
302
902
P3
211
222
P4
002
433
P0
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
When p1 request(1,0,2)
Check that Request Available (that is, (1, 0, 2) (3, 3, 2) true
P0
Allocation
Need
Available
ABC
ABC
ABC
010
743
230
17
P1
302
020
P2
301
600
P3
211
011
4
P4
002
3
1
Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies safety
requirement
Deadlock detection
Allow system to enter deadlock state
Detection algorithm
Recovery scheme
Periodically invoke an algorithm that searches for a cycle in the graph. If there is a
adding
the
appropriate edge.
Several instances of a resource type:1. Available: A vector of length m indicates the number of available resources
of each type.
2. Allocation: An n x m matrix defines the number of resources of each type
currently allocated to each process.
3. Request: An n x m matrix indicates the current request of each process. If
Request [ij] = k, then process Pi is requesting k more instances of resource
type. Rj.
Detection algorithm
1. Let Work and Finish be vectors of length m and n,
respectively. Initialize Work= Available. For i= 0, 1, ...
n, if Allocation 0,
then Finish[i] =false; otherwise, Finish[i] = true.
2. Find an index i such that both
a. Finish[i] ==false
b. Request i Work
If no such i exists, go to step 4.
19
4. If Finish[i] ==false for some i, 1 i n, then the system is in a deadlocked state. Moreover,
if
Finish[i] ==false, then process P; is deadlocked.
This algorithm requires an order of m x n2 operations to detect whether the system is in a
deadlocked state.
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
P4;
processes
P0
through
three
resource
A (7 instances), B (2 instances), and C (6 instances)
types
P0
P1
P2
Allocation
Request
Available
ABC
ABC
ABC
010
000
000
200
303
202
000
P3
211
100
P4
002
002
Sequence <P0, P2, P3, P1, P4> will result in Finish[i] = true for all i
20
Request
ABC
P0
000
P1
201
P2
001
P3
100
P4
002
State of system
o Can reclaim resources held by process P0, but insufficient
resources to fulfil other processes; requests
o Deadlock exists, consisting of processes P1, P2, P3, and
P4
When a detection algorithm determines that a deadlock exists, several alternatives are
available. One possibility is to inform the operator that a deadlock has occurred and to let the
operator deal with the deadlock manually. Another possibility is to let the system recover
from the deadlock automatically. There are two options for breaking a deadlock one is simply
to abort one or more processes to break the circular wait. The other is to pre-empt some
resources from one or more of the deadlocked processes.
1. Process Termination-To eliminate deadlocks by aborting a process, we use one of two
methods. In both methods, the system reclaims all resources allocated to the terminated
processes.
Abort all deadlocked processes-This method clearly will break the deadlock cycle, but
at great expense; the deadlocked processes may have computed for a long time, and
the results of these partial computations must be discarded and probably will have to
be recomputed later.
Abort one process at a time until the deadlock cycle is eliminated. This method incurs
considerable overhead, since after each process is aborted, a deadlock-detection
algorithm must be invoked to determine whether any processes are still deadlocked.
In which order should we choose to abort?
o Priority of the process
o How long process has computed, and how much longer to completion
o Resources the process has used
o Resources process needs to complete
o how many processes will need to be terminated
o Is process interactive or batch?
2. Resource pre emption
To eliminate deadlocks using resource pre-emption, we successively pre-empt some
resources from processes and give these resources to other processes until the deadlock cycle
is broken.
If pre-emption is required to deal with deadlocks, then three issues need to be addressed:
Selecting a victim- Which resources and which processes are to be pre-empted? As in
process termination, we must determine the order of pre-emption to minimize cost.
Cost factors may include such parameters as the number of resources a deadlocked
process is holding and the amount of time the process has thus far consumed during
its execution.
22
Rollback- If we pre-empt a resource from a process, what should be done with that
process? Clearly, it cannot continue with its normal execution; it is missing some
needed resource. We must roll back the process to some safe state and restart it from
that state.
Since, in general, it is difficult to determine what a safe state is, the simplest
solution is a total rollback: abort the process and then restart it. Although it is more
effective to roll back the process only as far as necessary to break the deadlock, this
method requires the system to keep more information about the state of all running
processes.
Starvation- How do we ensure that starvation will not occur? That is, how can we
guarantee that resources will not always be pre-empted from the same process?
5. CONCLUSION
23
REFERENCES
24
25