CH_6_OS
CH_6_OS
Deadlock
Deadlock Handling Techniques
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• Recovery from Deadlock
Deadlock Prevention
• Deadlock prevention and avoidance are strategies used in
computer systems to ensure that different processes can run
smoothly without getting stuck waiting for each other forever.
Think of it like a traffic system where cars (processes) must move
through intersections (resources) without getting into a gridlock.
• Necessary Conditions for Deadlock
• Mutual Exclusion
• No Preemption
• Circular Wait
1. Mutual Exclusion
• Mutual section from the resource point of view is the
fact that a resource can never be used by more than
one process simultaneously which is fair enough but
that is the main reason behind the deadlock. If a
resource could have been used by more than one
process at the same time then the process would have
never been waiting for any resource.
• However, if we can be able to violate resources
behaving in the mutually exclusive manner then the
deadlock can be prevented.
2. Hold and Wait
R1 R2 R3 R1 R2 R3
P1 0 1 0 1 0 0
P2 1 0 0 0 0 1
P3 0 0 1 0 1 0
Question for RAG
Process Allocation Request
Resource Resource
R1 R2 R3 R1 R2 R3
P1 0 1 0 1 0 0
P2 1 0 0 0 0 1
P3 0 0 1 0 1 0
P4 0 0 1 0 0 0
Bankers Algorithm
• Banker’s Algorithm is a resource allocation and deadlock avoidance
algorithm used in operating systems. It ensures that a system
remains in a safe state by carefully allocating resources to
processes while avoiding unsafe states that could lead to
deadlocks.
• The Banker’s Algorithm is a smart way for computer systems to
manage how programs use resources, like memory or CPU time.
• It helps prevent situations where programs get stuck and can not
finish their tasks. This condition is known as deadlock.