Professional Documents
Culture Documents
Deadlock
A process in operating system uses resources in the following way.
1. Requests a resource
2. Use the resource
3. Releases the resource
A deadlock is a situation in which more than one process is blocked
because it is holding a resource and also requires some resource that
Operating System is acquired by some other process. Therefore, none of the processes
gets executed.
Unit-III
1 2
Example
Necessary Conditions for Deadlock
The four necessary conditions for a deadlock to arise are as follows.
1. Mutual Exclusion: Only one process can use a resource at any
given time i.e. the resources are non-sharable.
2. Hold and wait: A process is holding at least one resource at a
time and is waiting to acquire other resources held by some other
process.
3. No preemption: The resource can be released by a process
voluntarily i.e. after execution of the process. Process 1 holds "Resource 1" and needs "Resource 2" while Process 2
4. Circular Wait: A set of processes are waiting for each other in a holds "Resource 2" and requires "Resource 1". This creates a situation of
deadlock because none of the two processes can be executed. Since the
circular fashion. For example, lets say there are a set of
resources are non-shareable they can only be used by one process at a
processes {P0,P1,P2,P3} such that P0 depends time(Mutual Exclusion). Each process is holding a resource and waiting
on P1, P1 depends on P2, P2 depends on P3 and P3 depends for the other process the release the resource it requires. None of the two
on P0. This creates a circular relation between all these processes processes releases their resources before their execution and this creates a
and they have to wait forever to be executed. circular wait. Therefore, all four conditions are satisfied.
3 4
1
11/10/2022
Deadlock Prevention : 2. The process will make a new request for resources after
Deadlock can be prevent by eliminating any of the four dead lock releasing the current set of resources. This solution may lead
conditions. to starvation.
Eliminate Mutual Exclusion Eliminate No Preemption
It is not possible to dis-satisfy the mutual exclusion because some Preempt resources from the process when resources required
resources, such as the tape drive and printer, are inherently non- by other high priority processes.
shareable. (spooling) Eliminate Circular Wait
Eliminate Hold and wait Each resource will be assigned with a numerical number. A
1. Allocate all required resources to the process can request the resources increasing/decreasing. order
process before the start of its execution, of numbering.
this way hold and wait condition is For Example, if P1 process is allocated R5 resources, now
eliminated but it will lead to low device next time if P1 ask for R4, R3 lesser than R5 such request will
utilization. for example, if a process not be granted, only request for resources more than R5 will
requires printer at a later time and we be granted.
have allocated printer before the start
of its execution printer will remain
blocked till it has completed its
7 8
execution.
2
11/10/2022
Deadlock Avoidance
1. Resource allocation Graph
2. Banker's Algorithm
Resource Allocation Graph
The resource allocation graph is the pictorial representation of the
state of a system. The resource allocation graph is the complete
information about all the processes which are holding some
resources or waiting for some resources. There are two types of edges in RAG –
1. Assign Edge – If you already assign a resource to a process then it
RAG contains vertices and edges. In RAG vertices are two type –
is called Assign edge.
1. Process vertex – Every process will be represented as a process
2. Request Edge – It means in future the process might want some
vertex. Generally, the process will be represented with a circle.
resource to complete the execution, that is called request edge.
2. Resource vertex – Every resource will be represented as a resource
vertex. It is also two type –
Single instance type resource – It represents as a box, inside the
box, there will be one dot. So the number of dots indicate how many
instances are present of each resource type.
Multi-resource instance type resource – It also represents as a box,
inside the box, there will be many dots present. 9 10
11 12
3
11/10/2022