2078 9

CSC264 · 2078 · 5 marks

What is resource allocation graph? Explain the process of detecting deadlocks when there is single instance of each resources with suitable example?

What is resource allocation graph? Explain the process of detecting deadlocks when there is single instance of each resources with suitable example? [5]

Operating SystemsChapter 3: Process DeadlocksHandling Deadlocks

Quick answer

A Resource Allocation Graph is a directed graph used to precisely describe and detect deadlocks in a system. It consists of: Vertices (V); P = {P1, P2,; R = {R1, R2,.

Resource Allocation Graph and Deadlock Detection (Single Instance)

Resource Allocation Graph (RAG)

A Resource Allocation Graph is a directed graph used to precisely describe and detect deadlocks in a system. It consists of:

  • Vertices (V): Two types:

    • P = {P1, P2, ..., Pn} - set of all active processes (represented as circles)
    • R = {R1, R2, ..., Rm} - set of all resource types (represented as rectangles)
  • Edges (E): Two types:

    • Request Edge: Pi → Rj (process Pi is requesting resource Rj)
    • Assignment Edge: Rj → Pi (resource Rj is assigned to process Pi)

Key Rule: If the RAG contains no cycle, no deadlock exists. If it contains one or more cycles, a deadlock exists (when each resource has only a single instance).


Deadlock Detection with Single Instance of Each Resource

When there is only one instance of each resource type, we construct a resource allocation graph and check for cycles. Any process that is part of a cycle is deadlocked.


Example

Consider a system with 7 processes (A to G) and 6 resources (R to W) with the following state:

ProcessHoldsWants
ARS
BNothingT
CNothingS
DUS and T
ETV
FWS
GVU

Step 1: Draw the RAG

Assignment Edges (Resource → Process):

  • R → A
  • U → D
  • T → E
  • W → F
  • V → G

Request Edges (Process → Resource):

  • A → S
  • B → T
  • C → S
  • D → S, D → T
  • E → V
  • F → S
  • G → U

Step 2: Trace for Cycles

Tracing the graph:

D → T → E → V → G → U → D   (Cycle Found!)

This forms a cycle: D → T → E → V → G → U → D

Step 3: Identify Deadlocked Processes

The processes involved in the cycle are:

D, E, and G are deadlocked.

  • Process D holds U, wants T
  • Process E holds T, wants V
  • Process G holds V, wants U

Each is waiting for a resource held by another in the cycle, and none can proceed.

Processes A, B, C, and F are not deadlocked (they are not part of any cycle), even though they may be waiting.


Conclusion

In a single-instance resource system, deadlock detection reduces to cycle detection in the Resource Allocation Graph. If a cycle exists, all processes in that cycle are deadlocked.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.