Deadlock Q+P
Deadlock Q+P
2. Describe the resource allocation graph and its role in detecting deadlocks.
The resource allocation graph is a directed graph used to represent the allocation and request
relationships between processes and resources in a system. It is a visual and analytical tool
for understanding potential deadlock situations.
Structure:
Nodes are categorized into two types: processes (denoted as circles) and resources
(denoted as squares or rectangles).
Edges indicate relationships:
A directed edge from a process to a resource represents a resource request (P → R).
A directed edge from a resource to a process represents a resource allocation (R →
P).
Deadlock Avoidance: This method relies on careful runtime analysis to ensure resources are
allocated safely. The Banker's Algorithm is an example:
Processes must declare their maximum resource needs upfront.
The system dynamically assesses whether granting a resource request will
leave the system in a safe state.
For example, if a process requests resources, the system evaluates whether
sufficient resources will remain available to meet the needs of other processes.
4. Discuss the concept of deadlock detection and recovery. How can a system recover from
a deadlock?
Deadlock detection involves techniques to monitor resource allocation and identify the
presence of deadlocks. Recovery strategies help resolve deadlock situations.
Detection: The operating system uses algorithms to periodically analyze resource allocation.
For instance:
o Wait-for Graphs: This method constructs a graph showing which processes are
waiting for resources held by other processes. Cycles in the graph indicate
deadlocks.
o Resource Allocation Matrices: These matrices track the status of resources to
identify deadlocks.
Recovery: Once a deadlock is detected, the system can recover using one of the following
approaches:
- Terminate Processes: One or more processes involved in the deadlock are
terminated to release their resources. The selection of processes can be based
on priority, execution time, or resource usage.
- Resource Preemption: Resources held by processes are forcibly taken and
allocated to other processes. Preemption might require processes to save their
states so they can resume later.
Both detection and recovery come with trade-offs. Detection methods require periodic
system checks, which can consume processing power. Recovery methods may impact
performance and cause data inconsistency.
Deadlock
Aspect Deadlock Avoidance Deadlock Detection
Prevention
Proactive
approach— Proactive approach—
Reactive approach—
eliminates one or analyzes resource
Approach detects deadlocks after
more necessary requests at runtime to
they occur.
conditions for ensure safety.
deadlocks.
Prevents mutual
Allows conditions to All conditions are
Necessary exclusion, hold-and-
exist but ensures safe allowed, leading to
Conditions wait, no preemption,
resource allocation. deadlock occurrence.
or circular wait.
Reduces system
Offers greater
High flexibility since
System flexibility by
flexibility by
resources are allocated
Flexibility restricting resource
allowing dynamic
freely.
allocation. allocation.
Complex—requires
Relatively simple— continuous Moderate—periodic
Implementation
imposes constraints monitoring and checks are required to
Complexity
on resource usage. analysis of system detect deadlocks.
state.
- Enforcing resource
- Banker's Algorithm
ordering (e.g., R1
to ensure safe - Using wait-for graphs
must be requested
resource allocation. to detect cycles.
Examples before R2).
- Declaring maximum - Maintaining resource
- Releasing all held
resource needs allocation matrices.
resources before
upfront.
requesting more.
Might lead to under- Increases overhead Recovery processes
Impact on utilization of due to continuous might temporarily
Performance resources due to monitoring and impact system
restrictions. evaluation. performance.
Recovery mechanisms
No recovery required No recovery required like terminating
Recovery
since deadlocks are as deadlocks are processes or resource
Mechanism
prevented. avoided. preemption are
necessary.
Suitable for systems Ideal for systems
Best for systems
where resource needs where deadlock
Suitability with low resource
can be declared in detection and recovery
contention.
advance. are manageable.
Limits resource Adds overhead due to
Requires additional
utilization; might runtime analysis;
Trade-offs system resources for
delay process requires safe state
detection and recovery.
execution. enforcement.
Requires strict
Requires detailed Needs periodic
design rules (e.g.,
System Design information about detection algorithms
resource ordering
Requirement resource and recovery
and no hold-and-
requirements. mechanisms.
wait).