0% found this document useful (0 votes)
19 views

Notes Deadlock PDF

Deadlock means

Uploaded by

Alijan Jan
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)
19 views

Notes Deadlock PDF

Deadlock means

Uploaded by

Alijan Jan
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/ 5

DEADLOCKS

Deadlock
A process in operating system uses resources in the following way.
1) Requests a resource
2) Use the resource
3) Releases the resource
Deadlock is a situation where a set of processes are blocked because each process is holding
a resource and waiting for another resource acquired by some other process.

For example, in the below diagram, Process 1 is holding Resource 1 and waiting for resource
2 which is acquired by process 2, and process 2 is waiting for resource 1

Deadlock can arise if the following four conditions hold simultaneously (Necessary
Conditions)
Mutual Exclusion: One or more than one resource are non-shareable (Only one process can
use at a time)
Hold and Wait: A process is holding at least one resource and waiting for resources.
No Preemption: A resource cannot be taken from a process unless the process releases the
resource.
Circular Wait: A set of processes are waiting for each other in circular form.
Methods of Handling Deadlock
1) Deadlock prevention or avoidance: The idea is to not let the system into a deadlock
state.
One can zoom into each category individually, Prevention is done by negating one of above
mentioned necessary conditions for deadlock.

Deadlock Avoidance Algorithm/Bankers Algorithm:


The algorithm employs several times varying data structures:

Available
A vector of length m indicates the number of available resources of each type.

Allocation -
An n*m matrix defines the number of resources of each type currently allocated to a
process.

Request -
An n*m matrix indicates the current request of each process

Deadlock Recovery:
A traditional operating system such as Windows doesn't deal with deadlock recovery as it is
a time and space-consuming process. Real-time operating systems use Deadlock recovery.
1. Killing the process -
Killing all the processes involved in the deadlock. Killing process one by one, After killing
each process check for deadlock again keep repeating the process till the system recovers
from deadlock. Killing all the processes one by one helps a system to break circular wait
condition.
2. Resource Preemption
Resources are preempted from the processes involved in the deadlock, preempted
resources are allocated to other processes so that there is a possibility of recovering the
system from deadlock. In this case, the system goes into starvation.
Resource Allocation Graph in Operating System
Given below are the components of RAG:
1. Vertices
2. Edges

Vertices
There is two kinds of vertices used in the resource allocation graph and these are:

 Process Vertices
 Resource Vertices
Process Vertices
These vertices are used in order to represent process vertices. The circle is used in order to
draw the process vertices and the name of the process is mentioned inside the circle.
Resource Vertices
These vertices are used in order to represent resource vertices. The rectangle is used in
order to draw the resource vertices and we use dots inside the circle to mention the
number of instances of that resource.

In the system, there may exist a number of instances and according to them, there are two
types of resource vertices and these are single instances and multiple instances.

Single Instance
In a single instance resource type, there is a single dot inside the box.
The single dot mainly indicates that there is one instance of the resource.
Multiple Instance
In multiple instance resource types, there are multiple dots inside the box, and these
Multiple dots indicate that there are multiple instances of the resources.

Single Instance RAG Example

suppose there are Four Processes P1 P2 P3 P4 and two resources R1 and R2, where P1 is
holding R1 and P2 is holding R2, P3 is waiting for R1 and R2 while P4 is waiting for resource
R1.

In the above example, there is no circular dependency so there are no chances for the
occurrence of deadlock.
Thus having cycled in single-instance resource type must be the sufficient condition for
deadlock.
Multiple Instance RAG Example

Suppose there are four processes P1, P2, P3, P4 and there are two instances of resource R1
and two instances of resource R2:

One instance of R2 is assigned to process P1 and another instance of R2 is assigned to


process P4, Process P1 is waiting for resource R1

You might also like