0% found this document useful (0 votes)
11 views15 pages

Term Paper

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)
11 views15 pages

Term Paper

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/ 15

DEADLOCK

Term/ Research Paper

Authors:
Romi kumari Md Ali Azam Shivam Raj Singh

12316334 12315411 12314364

School of CSE School of CSE School of CSE

[email protected] [email protected] [email protected]

1.ABSTRACT
Deadlock is a hypercritical problem in modern systems where the
process stops while it is waiting for resources which are held by some
another. In this study, we are going to examine how deadlock occurs.
How it can be detected, avoided, prevention, characterization of
deadlock. We will be demonstrating the graphs for the representation
of deadlock. We will also highlight what are their strengths and what
are their limitations. Using case studies, we will try to illustrate how
the deadlocks are arisen in the practical situations. Our main goal is to
emphasize of headlock mechanisms and create a more efficient
modern system environment that will be beneficial for us and other
users.
2. INTRODUCTION

A deadlock consists of a set of blocked processes or we can say


threads, each holds a resource and waits for the resource acquired any
another process to release the resource so they can use. It occurs when
a large number of processes try to get the limited number of
resources, as CPU, memory, input devices, output devices on same
time. The operating system can’t decide what action to take so it
aborts one process. We can understand it by this example, suppose
two trains are coming on the same track and there is only one track so,
they have to stop.

Diagram representation of deadlock

3. LITERATURE REVIEW
Till now, we have understood what is deadlock. Now we will see how
a deadlock is represented.
Deadlock is represented by directed graphs, commonly known as
“Resource Allocation Graph”.
These are set of vertices V and a set of edges E, where V is
partitioned into two types -
1. P - {P1, P2, …, Pn} the set contains all active processes.
2. R - {R1, R2, …, Rn} the set contains all resource types.
The set of edges are also defined into two types –
1. Request edge - Directed edge P->R. Process P requests for
instance of resource R. (Outside the process)
2. Assignment edge – Directed edge R->P. Resource R is
allocated to process P. (Inside the process)
Representation:
1. Process represented by a circle.

2. Resource represented by a square and inside


that the number of squares represent
instances.
3. Process P requests instance of R

-----------------

4. Process P holding an instance of resource R

-----------

What do these diagrams indicate and why we make them?


If a resource allocation graph has no cycle, then there is no deadlock.
If a resource allocation graph and if only one instance exists per
resource, then there is a “Deadlock”. But if a resource allocation
graph contains a cycle and if multiple instances are there then there is
a possibility that deadlock would be there.
Now that we have gathered basic knowledge about deadlock,
definition, representation. Now we will focus on some necessary
condition in detail for deadlock to occur.

4. MANAGING DEADLOCK
we will now see what are the methods for handling the
deadlocks. How we can deal with them.
So, there are four methods, through which we can handle the
deadlocks:
1. Prevention
2. Avoidance
3. Detection
4. Do nothing.
DEADLOCK PREVENTION

To prevent the deadlocks, we can restrain the ways that a request


can be made. Below are some methods, how deadlocks can be
prevented.
1. Mutual Exclusion: It says if one process is executing in its
critical section, then no other process can execute in this critical
section. This exclusion must be held for non-sharable resources.

2. Hold and wait: When a process is holding at least one resource


is waiting to acquire additional resources held by other
processes. Operating system allocates all its resources before the
process starts execution. It allows a process to request resources
only in one condition that is when the process has no resource.
But it has some drawbacks also, in this less resource is utilized,
and the main is that it can lead to starvation. When a process
doesn’t get the required resource which is needed for running
the process.

3. No Pre-emption: Process can release the resource once it has


completed its task. Resources cannot be pre-empted. If the
process is not completed then the resource cannot be released. If
one process goes to waiting state all its previously held
resources must be released implicitly. All resources previously
held by this process are implicitly released.

Pre-empted resources are added to the list of resources which


the process is waiting. A new thing, a process will be started
again when it acquires the old resources, as well as the new ones
that are requesting.
This protocol is often applied to that resources whose state can
be easily known and easily restored later, such as CPU registers
and memory space. It cannot generally be applied to such
resources as mutex locks and semaphores.

4. Circular Wait: It occurs when one or more processes wait in a


circular order for the resources they need. One way to avoid the
deadlock is we can request resources in strictly increasing or
decreasing order.
One major challenge in the scheme is determining the relative
ordering of the different resources. How it can be serially
ordered.
One way to ensure that this condition will not hold is to impose
a total ordering of all resource types and to require that each
process requests resources in an increasing order of
enumeration.

5.DEADLOCK AVOIDANCE

A deadlock avoidance policy gives permission to the resource


only if it can assure that the resource cannot lead to a deadlock
either immediately or in future. This means that a request is
granted one and only if it there is no possibility of deadlock
otherwise it will remain pending until and unless it is granted.
This is a kind of conservative approach because a process can
complete its operation without the requirement of maximum
num. of units declared by it.
Safe state: A state is known as safe state, if the system can
allocate the resources for each process up to its maximum
limitation in a systematical order to avoid the deadlock situation.
A deadlock state is considered as an unsafe state.
So, for this we use two algorithms:
1. Resource allocation graph: This is used for single if single
instance resource is there. We have explained it before

2. Banker’s Algorithm: This is used for when multiple instance


resource is there. Each process must prior their claim for
maximum use. In this, when a process requests a resource, it
may have to wait, and it any process gets all resources, they
must return them in a finite amount of time.

BANKER’S ALGORITHM

Let n = number of processes, and


m = number of resources types.
 Allocation: Resource that can be allocated
 Need: Process may need k more instance of resource to
complete its task.
 If request <= Need, process has exceeded maximum
Claim.
 If request <= Available, process must wait, since the
resources are not available.

Some important formulas:


Available = Available – Request
Allocation = Allocation + Request
Need = Need – Request
Need = Maximum – Allocation
Available = Available + Allocated
Safe -> the resources are allocated process
Unsafe -> Process must wait and the old allocated resources state
should be recovered.
We have to find safe sequence through the Banker’s algorithm.
Process Allocation Need Available Remaining
A B C A B C A B C A B C
P0 0 1 0 7 5 3
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 4 2 2
P4 0 0 2 5 3 3

Total <7 2 5>

We will see one example of Bankers’s algorithm in below page.


Suppose Total instance of A = 10, B = 5, C= 7;
Then,

Now, remaining = need – allocation;


In available, we will do
(Total instance given in question – total instance of allocation)
Allocation Need Available Remaining
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 4 2 2 2 1 1
P4 0 0 2 5 3 3 5 3 1

Total <7 2 5>


Process Allocation Need Available Remaining
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3
P1 2 0 0 3 2 2 5 3 2 1 2 2
P2 3 0 2 9 0 2 7 4 3 6 0 0
P3 2 1 1 4 2 2 7 4 5 2 1 1
P4 0 0 2 5 3 3 7 5 5 5 3 1

Total <7 2 5> 10 5 7

Now, we will try to find a safe sequence for checking if a deadlock


occurs or not. In available the executed process’s allocation will be
added. Like if we executed P1 first, so A = 3+2, B= 3 + 0, C = 2 + 0

Safe sequence: P1->P4>P4->P0->P2


It can be different also.

But this will work only if the instance given for each resource is
static, but in real-world scenario this doesn’t work. Here resources are
instantiated directly on run – time, that means dynamically. So, it can
be used in statically only and only in theory. However, we can create
a program but this doesn’t work in real-world scenario.

6.DEADLOCK DETECTION
For the detection of deadlock, the system must be providing some
conditions such as any algorithm to recovering from the deadlock. An
algorithm that examines the current state of system to check whether a
deadlock has occurred or not. It works by regularly checking the state
of the processes.
If the detection algorithms are invoked randomly then it is hard to tell
that deadlock is occurred by which process. But when the detection
algorithms is invoked for every resource request then a overhead will
occur in computation time
We can use an alternate to invoke the algorithm when CPU utilization
drops below 40%.
It improves the stability of the system because it is a main concern in
the operating system. Also, these are easily implemented and can be
used on a large range of and also with the system with different
resource allocation and synchronization requirements.
It has some disadvantages also. It can introduce performance
overhead, because the system regularly checks for deadlocks and it
should take appropriate action. Some algorithms are complex to
implement and requires good understanding of the system and its
working. Deadlock detection algorithms are not perfect sometimes as
it can create illusion.
Sometimes they fail to indicate the presence of deadlock whether they
exist or not. It totally depends on some particular requirements of the
system. Lastly, these detections are important for identifying the
situations whether the processes get stuck waiting for any resource.
The wait-for graph scheme is not applicable to a resource-allocation
system with multiple instances of each resource type. The graph is
obtained by removing the resource nodes from a resource-allocation
graph and collapsing the appropriate edges
Wait-for graph is used to detect the deadlock.

7.RECOVERY FROM DEADLOCK


In the modern world, where everything is being done digitally and in
the multitasking environment, deadlock is an unwanted situation that
can halt operations. When more than one processes compete for the
access to resources and they fall in the waiting state. For maintaining
the smooth functions on our system, recovery from deadlock is
necessary.
Recovery from deadlock includes some algorithms that are designed
to detect and mitigate the deadlock that has occurred.
Two approaches are there:
1. Process termination: Suppose there is a deadlock situation and
they created a circular wait. So, this approach terminates the
process to break the circular wait

2. Resource Pre-emption: In this approach pre-empted resources


are given to other process who need them.
In this resource pre-emption, some resources are pre-empted and then
distributed to the processes till the cycle is broken. This can raise
three issues that need to be addressed:
1. To identify which resource and processes are to be pre-empted?
2. Suppose we are pre-empting a resource from any of the process,
what should be done with that particular process. - Rollback
3. Also, an important situation “Starvation” can occur. How we
can ensure that this situation will not occur.

Starvation occurs when a process is restricted to access the


resource which is required to proceed. This condition happens
because other processes are being prioritized over the starving
process. Basically, this situation occurs because of scheduling
policies. Methods are there for resolving this also. But, one or
more process will suffer infinitely.
8.DISCUSSION

It is important to address the resolve the deadlock solution. It must be


resolved. It can be analyzed by four important conditions that are-
mutual exclusion, hold and wait, no pre-emption and the circular wait.
Deadlocks can affect the system in multiple ways. In banks or
healthcare system, it can cause data loss and delays also that is not
good for maintain good system environment.
Many methods are introduced to detect, prevent, and recover from the
deadlock. Such as Banker’s algorithm, wait-for-graphs, resource
allocation graph, safety algorithm. In real-world scenario, deadlock
handling is an important part. In handling a process would be
terminated or resources will be pre-empted but it will maintain the
operating part of the system. Research is necessary to develop
efficient algorithm, that can handle the complexity issues, parallel
processing. The concept of deadlock problems, are mostly seen in
supply chain management.
As technology is evolving day-by-day, our strategies should be also
increased. Ensuring that our system is working efficiently without any
problem or without halting any operation. How it can be resolved that
systems remain reliable and work against without the fear of deadlock

9.CONCLUSION

A deadlock state occurs when two or more processes are waiting for
some particular resources. We have to use some protocol, algorithms,
methods to prevent or avoid it, or we can do one more thing first put
the system in deadlock and then detect it, and then only try to recover
from that.
Also, we can ignore the problem and simultaneously, and then we can
pretend like nothing happened. And as usual we can work with our
computer ignoring that deadlock. This is used by the most operating
system, including Linux and Windows.
A method for avoid deadlocks, rather than prevention from them,
requires that the operating system have a priority information about
how each process will utilize system resources.
Deadlock can occur in four conditions – mutual exclusion, hold-and-
wait, no-preemption and circular wait. One of these conditions must
be fulfilled. As we have discussed earlier.
Many researchers have argued that these basic approaches are not
sufficient is we are using it alone. We have to use these approaches in
combination but we can choose an optimal approach to solve this.
REFERENCES:

1. Dijkstra, E.W. (1965). Co-operating Sequential Processes Academic

Press, London, UK

2. Coffman, E.G., Elphick, M.J., Shoshani, A. (1971), System Deadlocks

Computing Surveys, 3(2), pp. 67-78, June 1971.

3. Tanenbaum, A. S. (1992). Modern Operating Systems. Englewood

Cliffs, NJ: Prentice Hall.

4. Operating System Concepts, 8th Edition by ABRAHAM

SILBERSCHATZ, PETER BAER GALVIN, GREG GAGNE

5. Geeks for geeks

You might also like