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

Resource Allocation Graph (RAG) in Operating System

A Resource Allocation Graph (RAG) is a visual tool used in operating systems to illustrate the relationships between processes and resources, aiding in deadlock detection. It consists of process and resource vertices connected by edges that indicate resource allocation and requests. The presence of cycles in the graph can indicate potential deadlocks, depending on whether resources are single or multi-instance types.

Uploaded by

pingalesai9
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)
8 views

Resource Allocation Graph (RAG) in Operating System

A Resource Allocation Graph (RAG) is a visual tool used in operating systems to illustrate the relationships between processes and resources, aiding in deadlock detection. It consists of process and resource vertices connected by edges that indicate resource allocation and requests. The presence of cycles in the graph can indicate potential deadlocks, depending on whether resources are single or multi-instance types.

Uploaded by

pingalesai9
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/ 8

Search...

Resource Allocation Graph (RAG) in Operating

y
S stem

Last Updated : 04 Feb, 2025

A Resource Allocation Graph (RAG) is a visual way to understand how


resources are assigned in an operating s ystem. Instead of using only
tables to show which resources are allocated, requested, or available,
the RAG uses nodes and edges to clearly illustrate relationships
between processes and their required resources.

Although the Banker’s algorithm which is known for deadlock

avoidance often relies on tables for simplicity. RAGs primarily help in


detecting deadlocks by visually representing the relationships
between processes and resources, making it easier to identify
potential deadlock conditions.

A Resource Allocation Graph shows which resources are held by


which processes and which processes are waiting for specific
types of resources, including how many resources are available,
how many are allocated, and what each process needs.

It’s a straightforward tool for visualizing potential deadlocks in an


operating s ystem since the graph can make deadlock situations
more obvious than a table might.

By using an RAG, you can see how resource allocation and


requests affect the entire system.

RAG uses vertices to represent processes and resources, and


edges to connect them, creating a straightforward picture of
Open In App
resource allocation within the operating system.

T ypes of Vertices in RAG


In a Resource Allocation Graph, there are two types of vertices

1. Process Verte x: Every process will be represented as a process


vertex. Generally, the process will be represented with a circle.

2. Resource Verte x: Every resource will be represented as a resource


vertex. It is also two types:

Single Instance T ype Resource: A Single Instance Resource refers


to a type of resource in the system that has only one available
instance or copy. In the Resource Allocation Graph (RAG), a single
instance resource is represented as a single resource node, and
only one process can be assigned to this resource at any time.
Multi-Resource Instance T ype Resource: A Multi Instance
Resource refers to a type of resource that has multiple instances
available. In a Resource Allocation Graph (RAG), a multi-instance
resource has multiple resource nodes connected to process
nodes, allowing multiple processes to request and hold instances
of that resource simultaneously.

T ypes of Edges in RAG Open In App


Now coming to the edges of RAG. There are two t ypes of edges in

RAG:

Assign Edge: If you already assign a resource to a process then it is


called Assign edge. This is shown by an arrow from the resource
vertex to the process vertex.

Request Edge : A request edge represents that a process is


currently requesting a resource. This is shown by an arrow from
the process vertex to the resource vertex.

So, if a process is using a resource, an arrow is drawn from the


resource node to the process node. If a process is requesting a
resource, an arrow is drawn from the process node to the resource
node.

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.

Here's another example, that shows Processes P1 and P2 acquiring


resources R1 and R2 while process P3 is waiting to acquire both
resources. In this example, there is no deadlock because there is no
circular dependency. So cycle in single-instance resource type is the
sufficient condition for 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)

So there is no deadlock in this RAG. Even though there is a cycle,


still there is no deadlock. Therefore in multi-instance resource
cycle is not sufficient condition for deadlock.

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.

Deadlock Detection using Resource Allocation Graph

A Resource Allocation Graph (RAG) is used to detect deadlocks by


analyzing the relationships between processes and resources in a
system. It visually represents how resources are allocated and
requested.

If graph contains no c ycles → no deadlock.

If graph contains a c ycle → if only one instance per resource type,


then deadlock.
if several instances per resource type, possibility of deadlock

Figure given below is an example of System in a Deadlock because


all processes are blocked and cannot proceed

P1 is waiting for R2, held by P2.


P2 is waiting for R1, held by P1.
P3 is waiting for R3, whichOpen
is also
Inpart
App of this cycle.
RAG with Deadlock

Following is an example of Resource Allocation Graph with a cycle


but no Deadlock

The system has enough resources to break the cycle.


At least one process in the cycle can complete and release
resources, allowing the remaining processes to proceed.

RAG with a cycle but no Deadlock

GATE CS Corner Questions

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

You might also like