6 Deadlock Management

Operating Systems · Unit 6

Deadlock Management

Exam-focused notes for Deadlock Management (Operating Systems, BIT204): what the TU syllabus asks and how it has actually been tested, with 5 solved past questions from this unit.

Deadlock Management in short

A deadlock is a state where a group of processes wait for each other forever. This chapter explains why it happens, how to detect it, how to avoid it, and how to recover.

Deadlock Management: notes

Deadlock definition

A set of processes is in deadlock when every process waits for a resource that another process in the set holds. None of them can go on, so all wait forever.

Example: process P1 holds a printer and asks for a scanner. Process P2 holds the scanner and asks for the printer. Neither will release what it has, so both are stuck.

A process uses a resource in three steps: request, use and release. Deadlock happens in the request step.

Necessary conditions for deadlock

Deadlock can occur only if all four Coffman conditions hold at the same time.

  • Mutual exclusion: at least one resource can be used by only one process at a time.
  • Hold and wait: a process holds one resource while it waits for another.
  • No preemption: a resource cannot be taken away by force. The holder must release it.
  • Circular wait: a closed chain exists, where each process waits for a resource held by the next one.

Prevention works by making at least one of these conditions impossible. For example, a process can be forced to request all its resources at once (breaks hold and wait). Resources can also be numbered, and processes must ask in increasing order (breaks circular wait).

Resource Allocation Graph

A resource allocation graph (RAG) is a directed graph that shows which resource is held by which process.

  • Processes are drawn as circles.
  • Resources are drawn as rectangles, with a dot for each instance.
  • A request edge goes from a process to a resource ($P_i \to R_j$).
  • An assignment edge goes from a resource to a process ($R_j \to P_i$).

Reading the graph:

  • If the graph has no cycle, there is no deadlock.
  • If there is a cycle and each resource has only one instance, there is a deadlock.
  • If there is a cycle and resources have several instances, deadlock is possible but not certain.

What this unit covers

  • Deadlock definition
  • Necessary conditions for deadlock
  • Resource Allocation Graph
  • Deadlock detection methods
  • Deadlock recovery techniques
  • Banker's Algorithm
  • Deadlock versus starvation

Banker's Algorithm

2082 · 5 marks

Discuss about working mechanism of banker’s algorithm. [5]

The Banker's Algorithm, proposed by Dijkstra, is a deadlock avoidance algorithm used in operating systems. It is named after a banking system where a banker grants loans only if the total amount requested does not exceed available resources, ensuring the bank can always satisfy all customers. The...

Open this answer on its own page →

2079 · 10 marks

Resource Allocation Graph and Deadlock Analysis

A Resource Allocation Graph is a directed graph used to model and detect deadlocks in a system. Components: - Process nodes $P = {P1, P2, \dots, Pn}$ drawn as circles. - Resource nodes $R = {R1, R2, \dots, Rm}$ drawn as rectangles, with dots inside representing the number of instances. - Requ...

Open this answer on its own page →

Deadlock versus starvation

2080 · 5 marks

Differentiate between deadlock and starvation? Discuss the process of detecting deadlocks when there are multiple resources of each type. [5]

--- Aspect Deadlock Starvation --------- Definition A situation where a set of processes are permanently blocked, each waiting for a resource held by another process in the set A situation where a process waits indefinitely because other processes keep getting the resource it needs Cause Circular...

Open this answer on its own page →

Deadlock definition

2078 · 5 marks

what is deadlock? What ate necessary conditions for deadlock? Explain. [5]

Show solved answer

Deadlock

Definition

A deadlock is a situation in a multiprogramming environment where a set of processes are blocked permanently because each process in the set is waiting for a resource that is held by another process in the same set. None of the processes can proceed, and they wait indefinitely.

Example: Process P1 holds Resource R1 and waits for R2, while Process P2 holds R2 and waits for R1. Neither can proceed.


Necessary Conditions for Deadlock (Coffman Conditions)

Deadlock can occur if and only if all four of the following conditions hold simultaneously:


1. Mutual Exclusion

  • At least one resource must be held in a non-shareable mode.
  • Only one process can use the resource at a time.
  • If another process requests that resource, it must wait until the resource is released.

Example: A printer can be used by only one process at a time.


2. Hold and Wait

  • A process must be holding at least one resource and waiting to acquire additional resources that are currently held by other processes.
  • The process does not release the resources it already holds while waiting.

Example: P1 holds R1 and is waiting for R2.


3. No Preemption

  • Resources cannot be forcibly taken away from a process.
  • A resource can only be released voluntarily by the process holding it, after it has completed its task.

Example: A process holding a file lock cannot be forced to release it.


4. Circular Wait

  • A set of processes {P0, P1, P2, ..., Pn} must exist such that:
    • P0 is waiting for a resource held by P1
    • P1 is waiting for a resource held by P2
    • ...
    • Pn is waiting for a resource held by P0
  • This forms a circular chain of waiting processes.

Example: P1 → waits for R2 (held by P2) → waits for R1 (held by P1)


Summary Table

ConditionDescription
Mutual ExclusionResource held in non-shareable mode
Hold and WaitProcess holds resource while waiting for more
No PreemptionResources cannot be forcibly taken
Circular WaitCircular chain of processes waiting for resources

Note: All four conditions must hold simultaneously for deadlock to occur. Preventing even one condition is sufficient to prevent deadlock.

Open this answer on its own page →

Necessary conditions for deadlock

0 · 5 marks

Why do deadlock occurs? How can you detect and recover from deadlock. [5]

A deadlock occurs when a set of processes are permanently blocked, each waiting for a resource held by another process in the set. Deadlock arises when all four Coffman conditions hold simultaneously: Condition Description ------ Mutual Exclusion At least one resource is held in a non-shareable m...

Open this answer on its own page →