Methods for Handling Deadlocks
Methods for Handling Deadlocks
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• Recovery from Deadlock
Deadlock Prevention
• Necessary Conditions for Deadlock
• Mutual Exclusion
• Hold and Wait
• No Preemption
• Circular Wait
• We can prevent a Deadlock by eliminating any of
the above four conditions.
Deadlock Avoidance
• Deadlock prevention algorithm may lead to
low device utilization and reduces system
throughput.
• Avoiding deadlocks requires additional
information about how resources are to be
requested.
States
• Safe state( No deadlock)
It is a state where the operating system can avoid
unsafe and deadlocked states.
• Unsafe state (Deadlock)
It is a state where the operating system cannot
prevent processes from requesting resources in
such a way that any deadlock occurs.
• Deadlock state is a state where two or more
processes are blocked and waiting for each other
to release the resources they need to proceed.
Banker’s Algorithm
• Banker’s algorithm is a deadlock avoidance and
Detection algorithm.
• It is named so because this algorithm is
Banker’s Algorithm used in banking systems to
determine whether a loan can be granted or
not.
• Bankers’ Algorithm is a resource allocation and
deadlock avoidance algorithm that tests all
resource requests made by processes.
Banker’s Algorithm
• It checks for the safe state, and if granting a
request keeps the system in safe state, the
request is allowed.
• However, if no safe state exists, the request is
denied.
• The Banker’s Algorithm is a smart way for
computer systems to manage how programs
use resources, like memory or CPU time.
Components of the Banker’s Algorithm
1. Available
2. Max
3. Allocation
4. Need
Need [i, j] = Max [i, j] – Allocation [i, j]
So, the content of Need Matrix is:
Deadlock Detection
• When the system is in deadlock then one method is to
inform the operator and then operator deal with
deadlock manually.
• A Resource Allocation Graph (RAG) is used to detect
deadlocks by analyzing the relationships between
processes and resources in a system. It visually
represents how resources are allocated and requested.
• If graph contains no cycles → no deadlock.
• If graph contains a cycle → if only one instance per
resource type, then deadlock.
if several instances per resource type, possibility of
deadlock
Recovery from Deadlock
• Process termination:
One way to recover from a deadlock is to
terminate one or more of the processes involved in
the deadlock.
• By releasing the resources held by these
terminated processes, the remaining processes
may be able to continue executing.
• Resources preemption:
Resources can be forcibly taken away from one or
more processes and allocated to the waiting
processes.

deadlock in operating system ( os ).pptx

  • 1.
  • 2.
    Methods for HandlingDeadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock
  • 3.
    Deadlock Prevention • NecessaryConditions for Deadlock • Mutual Exclusion • Hold and Wait • No Preemption • Circular Wait • We can prevent a Deadlock by eliminating any of the above four conditions.
  • 4.
    Deadlock Avoidance • Deadlockprevention algorithm may lead to low device utilization and reduces system throughput. • Avoiding deadlocks requires additional information about how resources are to be requested.
  • 5.
    States • Safe state(No deadlock) It is a state where the operating system can avoid unsafe and deadlocked states. • Unsafe state (Deadlock) It is a state where the operating system cannot prevent processes from requesting resources in such a way that any deadlock occurs. • Deadlock state is a state where two or more processes are blocked and waiting for each other to release the resources they need to proceed.
  • 7.
    Banker’s Algorithm • Banker’salgorithm is a deadlock avoidance and Detection algorithm. • It is named so because this algorithm is Banker’s Algorithm used in banking systems to determine whether a loan can be granted or not. • Bankers’ Algorithm is a resource allocation and deadlock avoidance algorithm that tests all resource requests made by processes.
  • 8.
    Banker’s Algorithm • Itchecks for the safe state, and if granting a request keeps the system in safe state, the request is allowed. • However, if no safe state exists, the request is denied. • The Banker’s Algorithm is a smart way for computer systems to manage how programs use resources, like memory or CPU time.
  • 9.
    Components of theBanker’s Algorithm 1. Available 2. Max 3. Allocation 4. Need
  • 10.
    Need [i, j]= Max [i, j] – Allocation [i, j] So, the content of Need Matrix is:
  • 17.
    Deadlock Detection • Whenthe system is in deadlock then one method is to inform the operator and then operator deal with deadlock manually. • A Resource Allocation Graph (RAG) is used to detect deadlocks by analyzing the relationships between processes and resources in a system. It visually represents how resources are allocated and requested. • If graph contains no cycles → no deadlock. • If graph contains a cycle → if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock
  • 18.
    Recovery from Deadlock •Process termination: One way to recover from a deadlock is to terminate one or more of the processes involved in the deadlock. • By releasing the resources held by these terminated processes, the remaining processes may be able to continue executing. • Resources preemption: Resources can be forcibly taken away from one or more processes and allocated to the waiting processes.