Resource Allocation Graph (RAG) in Operating System
Resource Allocation Graph (RAG) in Operating System
y
S stem
RAG:
x
E ample 1 (Single Instances RAG)
Open In App
If there is a cycle in the Resource Allocation Graph and each resource
in the cycle provides only one instance, then the processes will be in
deadlock. For example, if process P1 holds resource R1, process P2
holds resource R2 and process P1 is waiting for R2 and process P2 is
waiting for R1, then process P1 and process P2 will be in deadlock.
x
E ample 2 (Multi-instances RAG)
Open In App
From the above example, it is not possible to say the RAG is in a safe
state or in an unsafe state. So to see the state of this RAG, let's
construct the allocation matrix and request matrix.
The total number of processes are three: P1, P2 & P3 and the total
number of resources are two: R1 & R2.
Allocation matri x
For constructing the allocation matrix, just go to the resources and
see to which process it is allocated.
R1 is allocated to P1, therefore write 1 in allocation matrix and
similarly, R2 is allocated to P2 as well as P3 and for the remaining
element just write 0.
Open In App
Request matri x
In order to find out the request matrix, you have to go to the
process and see the outgoing edges.
P1 is requesting resource R2, so write 1 in the matrix and similarly,
P2 requesting R1 and for the remaining element write 0.
So now available resource is = (0, 0).
Checking deadlock (safe or not)
Above example is the same as the previous example except that, the
process P3 requesting for resource R1. So the table becomes as
shown in below. Open In App
So, the Available resource is = (0, 0), but requirement are (0, 1), (1, 0)
and (1, 0). So you can't fulfill any one requirement. Therefore, it is in
deadlock. Therefore every cycle in a multi-instance resource type
graph is not a deadlock. If there has to be a deadlock, there has to be
a cycle. So in case of RAG with multi-instance resource type, the
cycle is a necessary condition for deadlock but not sufficient.
Practicing the following questions will help you test your knowledge.
All questions have been asked in GATE in previous years or in GATE
Mock Tests. It is highly recommended that you practice them.
Open In App