The Wayback Machine - https://web.archive.org/web/20250117213519/https://www.geeksforgeeks.org/resource-allocation-graph-rag-in-operating-system/
Open In App

Resource Allocation Graph (RAG) in Operating System

Last Updated : 26 Dec, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.

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.

Resource Allocation Graph (RAG)

A Resource Allocation Graph shows which resources are held by which processes and which processes are waiting for specific types of resources. It’s a straightforward tool for visualizing potential deadlocks in an operating system 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. While tables are often better for large systems with many processes and resources, RAGs are ideal for smaller environments where a quick, visual understanding of resource management is more effective.

So, the resource allocation graph clearly shows the state of the system in terms of processes and resources, including how many resources are available, how many are allocated, and what each process needs. By visualizing this information as a graph, it can be easier to spot potential deadlocks than when looking at tables alone. However, tables are often more convenient for systems with many processes and resources, while RAGs are more helpful in smaller environments. As with any graph, a RAG uses vertices to represent processes and resources, and edges to connect them, creating a straightforward picture of resource allocation within the operating system.

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:

  • Single instance type resource: It represents a box, inside the box, there will be one dot. So the number of dots indicates 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.

Vertices in RAG

Types of Edges in RAG

Now coming to the edges of RAG. There are two types of edges in RAG:

  • Assign Edge: If you already assign a resource to a process then it is called Assign edge.
  • 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.

Edge in RAG

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)

Single instances RAG

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.

Single Instance Resource

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)

Multi-instances RAG

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.

Allocation & request matrix

  • The total number of processes are three: P1, P2 & P3 and the total number of resources are two: R1 & R2.
  • Allocation matrix
    • 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.
  • Request matrix
    • 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)

Checking deadlock

  • 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.

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.

Allocation

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.

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.

  1. GATE CS 2009, Question 60
  2. GATE CS 2014 (Set 1), Question 65

Conclusion

A Resource Allocation Graph is an essential visualization tool in operating systems that helps highlight how resources are allocated to various processes. By illustrating which resources are in use, which are available, and what each process needs, RAGs make it easier to detect congestion, identify potential deadlocks, and improve overall system efficiency. Although tables are effective for large, complex environments, RAGs offer a clear, intuitive approach to resource management, ensuring better performance and security within the operating system.

Frequently Asked Questions on Resource Allocation Graph – FAQ’s

What is a cycle in a resource allocation graph?

A cycle in a resource allocation graph is a closed sequence of processes and resources where each process is waiting for a resource currently held by the next process in the cycle.

What is the difference between resource allocation graph and wait for graph?

A resource allocation graph represents processes and resources as separate nodes with edges indicating allocation or requests, whereas a wait-for graph represents only processes, with edges showing one process waiting for another to release resources.

What is meant by resource allocation?

Resource allocation is the process of assigning available resources to processes according to their requirements. It ensures that processes obtain the necessary resources to execute efficiently without unnecessary delays.


Our GATE 2026 Courses for CSE & DA offer live and recorded lectures from GATE experts, Quizzes, Subject-Wise Mock Tests, PYQs and practice questions, and Full-Length Mock Tests to ensure you’re well-prepared for the toughest questions.

Take the Three 90 Challenge! Complete 90% of the course in 90 days and earn a 90% refund. Stay motivated, track your progress, and make the most of your preparation time. Plus, enjoy exclusive features like:

--> All India Mock Test
--> Live GATE CSE & DA Mentorship Classes
--> Live Doubt Solving Sessions

Join now and stay ahead in your GATE 2026 journey!


Next Article
Article Tags :

Similar Reads

three90RightbarBannerImg