Open In App

Resource Allocation Graph (RAG) in Operating System

Last Updated : 25 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

As Banker’s algorithm using some kind of table like allocation, request, available all that thing to understand what is the state of the system. Similarly, if you want to understand the state of the system instead of using those table, actually tables are very easy to represent and understand it, but then still you could even represent the same information in the graph. That graph is called

Resource Allocation Graph (RAG)

A resource allocation graphs shows which resource is held by which process and which process is waiting for a resource of a specific kind. It is amazing and straight – forward tool to outline how interacting processes can deadlock. Therefore, resource allocation graph describe what the condition of the system as far as process and resources are concern like what number of resources are allocated and what is the request of each process. Everything can be represented in terms of graph. One of the benefit of having a graph is, sometimes it is conveivable to see a deadlock straight forward by utilizing RAG and however you probably won’t realize that by taking a glance at the table. Yet tables are better if the system contains bunches of process and resource and graph is better if the system contains less number of process and resource.

. So, resource allocation graph is explained to us what is the state of the system in terms of processes and resources. Like how many resources are available, how many are allocated and what is the request of each process. Everything can be represented in terms of the diagram. One of the advantages of having a diagram is, sometimes it is possible to see a deadlock directly by using RAG, but then you might not be able to know that by looking at the table. But the tables are better if the system contains lots of process and resource and Graph is better if the system contains less number of process and resource. We know that any graph contains vertices and edges.

Types of Vertices in RAG

So RAG also contains vertices and edges. In RAG vertices are two types

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

Vertices

How many Types of Edges are there 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: It means in future the process might want some resource to complete the execution, that is called request edge.

Edge

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

  • 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) –
  • hgh-1
  • 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

Previous Article
Next Article

Similar Reads

Difference between Static Allocation and Heap Allocation
Static Allocation v/s Heap Allocation Static Allocation: Static allocation is an allocation procedure that is used for the allocation of all the data objects at compile time. In this type of allocation, allocation of data objects is done at compile time only. As in static allocation, the compiler decides the extent of storage which cannot be change
3 min read
Buddy Memory Allocation Program | Set 1 (Allocation)
Prerequisite - Buddy System Question: Write a program to implement the buddy system of memory allocation in Operating Systems.Explanation - The buddy system is implemented as follows- A list of free nodes, of all the different possible powers of 2, is maintained at all times (So if total memory size is 1 MB, we'd have 20 free lists to track-one for
13 min read
Difference between Static allocation and Stack allocation
Static Allocation: Static allocation is a procedure which is used for allocation of all the data objects at compile time. Static allocation is possible only when the compiler knows the size of data object at compile time. In this type of allocation, formation of data objects is not possible under any circumstances at run time. In static allocation,
2 min read
Resource Allocation Techniques for Processes
The Operating System allocates resources when a program need them. When the program terminates, the resources are de-allocated, and allocated to other programs that need them. Now the question is, what strategy does the operating system use to allocate these resources to user programs? There are two Resource allocation techniques: 1. Resource parti
2 min read
Resource Allocation
To assign the available resources in an economic way is known as resource allocation. The planning of the activities and the resource required by these activities while taking into consideration both resources availability and project time is termed as resource allocation in project management. There are 2 parts of resource allocation: Strategic Pl
2 min read
Allocation of frames in Operating System
An important aspect of operating systems, virtual memory is implemented using demand paging. Demand paging necessitates the development of a page-replacement algorithm and a frame allocation algorithm. Frame allocation algorithms are used if you have multiple processes; it helps decide how many frames to allocate to each process. There are various
3 min read
Best-Fit Allocation in Operating System
INTRODUCTION: Best-Fit Allocation is a memory allocation technique used in operating systems to allocate memory to a process. In Best-Fit, the operating system searches through the list of free blocks of memory to find the block that is closest in size to the memory request from the process. Once a suitable block is found, the operating system spli
4 min read
Non-Contiguous Allocation in Operating System
Non-contiguous allocation, also known as dynamic or linked allocation, is a memory allocation technique used in operating systems to allocate memory to processes that do not require a contiguous block of memory. In this technique, each process is allocated a series of non-contiguous blocks of memory that can be located anywhere in the physical memo
6 min read
Resource Management in Operating System
Resource Management in Operating System is the process to manage all  the resources efficiently like CPU, memory, input/output devices, and other hardware resources among the various programs and processes running in the computer. Resource management is an important thing because resources of a computer are limited and multiple processes or users m
3 min read
RAG Full Form
RAG is the abbreviation for Resource Allocation Graph in operating systems. RAG is a directed graph which can be used to represent the state of a system in the form of picture. Deadlocks can be described more precisely in terms of a directed graph(RAG). The graph(V, E) consists a set of vertices which can be partitioned into two different types of
3 min read
Article Tags :