Resource Allocation Graph (RAG) (original) (raw)

Last Updated : 25 Oct, 2025

A Resource Allocation Graph (RAG) is a visual way to understand how resources are assigned in an operating system. 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.

Types of Vertices in RAG

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

**1. Process Vertex: Every process will be represented as a process vertex. Generally, the process will be represented with a circle.
**2. Resource Vertex: Every resource will be represented as a resource vertex. It is also two types:

frame_3197

Types of Vertices

Types of Edges in RAG

There are two types of edges in RAG:

frame_3196

Types of Edges

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.

Example 1: (Single Instances RAG)

frame_3195

Single Instance with deadlock

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.

frame_3194

Single Instance without 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.

Example 2: (Multi-instances RAG)

frame_3193

Multi Instances without deadlock

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.

frame_3204

Resource Allocation Table

Checking deadlock

frame_3192

Multi Instances with 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.

frame_3191

Resource Allocation Table

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.

Figure given below is an example of System in a Deadlock because all processes are **blocked and cannot proceed

RAG1

RAG with Deadlock

Following is an example of Resource Allocation Graph with a cycle but no Deadlock

RAG2

RAG with a cycle but no Deadlock