Click to edit Master title style
1
Dead-Locks in
Operating Systems
An Unconditional Waiting Situation
by
VENKATA SREERAM
Click to edit Master title style
2
What is a Dead-Lock ?
Deadlock is a situation where a set of processes are
blocked because each process is holding a resource
and waiting for another resource acquired by some
other process.
2
Click to edit Master title style
3
Realtime-Example of Deadlock
• Two Trains are Travelling on different Tracks. If a Crossing came, A Train
Must Hold or wait for sometime to continue the Journey. That waiting
situation Is Referred as “Deadlock” Situation.
• While, playing Chess – CHECKMATE is the deadlock situation. Where, there
is no chance of escaping and have to hold for sometime to move. 3
Click to edit Master title style
4
Deadlock Situation in Data-Base
• No Two Transactions takes place at a time in the Database. It hold one
transaction In the Queue to Proceed.
4
Click to edit Master title style
5
Conditions for Deadlock
What are the conditions that a Process Undergone Deadlock
situation. How can we Identify that a Process is in Deadlock
Situation ?
5
Click to edit Master title style
6
Conditions for Deadlock in OS
6
Mutual
Exclusion
Hold and
Wait
No
Preemption
Circular
Wait
Click to edit Master title style
7
Mutual-Exclusion
7
• When a Process is Accessing a
Shared Variable, the Process is
said to be in a CRITICAL
SITUATION
• One Process at a time can Use a
resource.
p1
p2
R1
R2
Click to edit Master title style
8
Hold and Wait
8
• A Process holding at least one resource is waiting to acquire
additional resources held by another processes.
• Printer needs scanned copy to Print and scanner wants a copy to
scan.
Click to edit Master title style
9
No Preemption
9
• A Resource can be released only voluntarily by the process holding
it, after that process has completed its task.
• Number of resources can be feasibly removed from a processor
holding it.
Click to edit Master title style
10
Circular Wait
10
• There exists a set { p1,p2,p3…pn }
of waiting processes such that p1
is waiting for a resource that Is
held by p2, p2 is waiting for a
resource that is held by p3.
• Pn is waiting for the resource pn-1
Click to edit Master title style
11
Resource-Allocation Graph
11
Resource Allocation Without cycles
• 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
dead lock.
Click to edit Master title style
12
Resource Allocation Graph
12
 Resource Allocation
graph contains cycles & but,
no deadlock.
Click to edit Master title style
13
How to Handle the Deadlocks ?
Deadlock Recovery
13
Deadlock Detection
Deadlock Avoidance
Deadlock Prevention
Click to edit Master title style
14
Deadlock Prevention
14
At least one of 4 deadlock conditions is
never satisfied.
Elimination of
 Mutual Exclusion
 Hold & Wait Condition
 No Preemption Condition
 Circular Wait
Click to edit Master title style
15
Deadlock Prevention
15
Mutual
Exclusion
We can deny this situation by simple protocol i.e.,
“ Convert All non-sharable resources to sharable Resources “
Click to edit Master title style
16
Deadlock Prevention
16
We can deny this situation with the following Protocols:
 A Process can Request the Resources only when the
Process has None.
 Each Process to request and be allocated all its Resources
before it begins Execution.
Hold and
Wait
Click to edit Master title style
17
Deadlock Prevention
17
To ensure that this condition does not hold, we use the following Protocol:
 We preempt the desired resources from the waiting process
and allocate them to the requesting Process.
No
Preemption
Click to edit Master title style
18
Deadlocks Prevention
18
We ensure that circular wait must not happened if we apply a simple solution:
 Numbering all the Resources types and each Process
Request resources in an Increasing order of enumeration.
Circular
Wait
Click to edit Master title style
19
Deadlock Avoidance
19
At least one of 4 deadlock conditions is
never satisfied.
Elimination of
 Mutual Exclusion
 Hold & Wait Condition
 No Preemption Condition
 Circular Wait
Click to edit Master title style
20
20
Deadlock can be avoided if certain
information about processes are available to
the operating system before allocation of
resources.
For every resource request, the system sees
whether granting the request will cause the
system to enter an unsafe state that means
this state could result in deadlock.
The system then only grants the requests that
will lead to safe states.
Deadlock Avoidance
Click to edit Master title style
2121
Deadlock Avoidance
Click to edit Master title style
22
22
Deadlock Avoidance
Click to edit Master title style
2323
Deadlock Avoidance
Click to edit Master title style
24
24
Deadlock Detection
Allow System to enter deadlock state
Detection algorithm
Recovery Scheme
Click to edit Master title style
25
25
Deadlock Detection
Click to edit Master title style
26
26
Deadlock Detection
Example for Detection Algorithm
Click to edit Master title style
2727
Deadlock Detection
Click to edit Master title style
28
28
Deadlock Detection
Once Deadlock has been
detected, Some Strategy is
needed for recovery. The
various approaches of
recovering from deadlocks are:
• Process Termination
• Resource Preemption
Click to edit Master title style
29
29
Deadlock Recovery
Process termination
occurs when
the process is terminated
The exit() system call is
used by most operating
systems for process
termination.
This process leaves the
processor and releases all
its resources.
Click to edit Master title style
3030
Deadlock Recovery
Click to edit Master title style
31
Deadlocks-Concept Overview
31
Beyond the concepts of Deadlocks, It was very easy to understand with Realtime concepts where
the resources has been allocated to the processors while performing operations in Operating
System.
We must ensure that the recovery Strategies of deadlocks and prevention, avoidance Algorithms
well by giving suitable examples.
Click to edit Master title style
32
“
Knowledge Increases by
Sharing but not by Saving ”
- Venkata Sreeram
18U91A584
32
Click to edit Master title style
33
😁Thank you !

DeadLock in Operating-Systems

  • 1.
    Click to editMaster title style 1 Dead-Locks in Operating Systems An Unconditional Waiting Situation by VENKATA SREERAM
  • 2.
    Click to editMaster title style 2 What is a Dead-Lock ? Deadlock is a situation where a set of processes are blocked because each process is holding a resource and waiting for another resource acquired by some other process. 2
  • 3.
    Click to editMaster title style 3 Realtime-Example of Deadlock • Two Trains are Travelling on different Tracks. If a Crossing came, A Train Must Hold or wait for sometime to continue the Journey. That waiting situation Is Referred as “Deadlock” Situation. • While, playing Chess – CHECKMATE is the deadlock situation. Where, there is no chance of escaping and have to hold for sometime to move. 3
  • 4.
    Click to editMaster title style 4 Deadlock Situation in Data-Base • No Two Transactions takes place at a time in the Database. It hold one transaction In the Queue to Proceed. 4
  • 5.
    Click to editMaster title style 5 Conditions for Deadlock What are the conditions that a Process Undergone Deadlock situation. How can we Identify that a Process is in Deadlock Situation ? 5
  • 6.
    Click to editMaster title style 6 Conditions for Deadlock in OS 6 Mutual Exclusion Hold and Wait No Preemption Circular Wait
  • 7.
    Click to editMaster title style 7 Mutual-Exclusion 7 • When a Process is Accessing a Shared Variable, the Process is said to be in a CRITICAL SITUATION • One Process at a time can Use a resource. p1 p2 R1 R2
  • 8.
    Click to editMaster title style 8 Hold and Wait 8 • A Process holding at least one resource is waiting to acquire additional resources held by another processes. • Printer needs scanned copy to Print and scanner wants a copy to scan.
  • 9.
    Click to editMaster title style 9 No Preemption 9 • A Resource can be released only voluntarily by the process holding it, after that process has completed its task. • Number of resources can be feasibly removed from a processor holding it.
  • 10.
    Click to editMaster title style 10 Circular Wait 10 • There exists a set { p1,p2,p3…pn } of waiting processes such that p1 is waiting for a resource that Is held by p2, p2 is waiting for a resource that is held by p3. • Pn is waiting for the resource pn-1
  • 11.
    Click to editMaster title style 11 Resource-Allocation Graph 11 Resource Allocation Without cycles • 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 dead lock.
  • 12.
    Click to editMaster title style 12 Resource Allocation Graph 12  Resource Allocation graph contains cycles & but, no deadlock.
  • 13.
    Click to editMaster title style 13 How to Handle the Deadlocks ? Deadlock Recovery 13 Deadlock Detection Deadlock Avoidance Deadlock Prevention
  • 14.
    Click to editMaster title style 14 Deadlock Prevention 14 At least one of 4 deadlock conditions is never satisfied. Elimination of  Mutual Exclusion  Hold & Wait Condition  No Preemption Condition  Circular Wait
  • 15.
    Click to editMaster title style 15 Deadlock Prevention 15 Mutual Exclusion We can deny this situation by simple protocol i.e., “ Convert All non-sharable resources to sharable Resources “
  • 16.
    Click to editMaster title style 16 Deadlock Prevention 16 We can deny this situation with the following Protocols:  A Process can Request the Resources only when the Process has None.  Each Process to request and be allocated all its Resources before it begins Execution. Hold and Wait
  • 17.
    Click to editMaster title style 17 Deadlock Prevention 17 To ensure that this condition does not hold, we use the following Protocol:  We preempt the desired resources from the waiting process and allocate them to the requesting Process. No Preemption
  • 18.
    Click to editMaster title style 18 Deadlocks Prevention 18 We ensure that circular wait must not happened if we apply a simple solution:  Numbering all the Resources types and each Process Request resources in an Increasing order of enumeration. Circular Wait
  • 19.
    Click to editMaster title style 19 Deadlock Avoidance 19 At least one of 4 deadlock conditions is never satisfied. Elimination of  Mutual Exclusion  Hold & Wait Condition  No Preemption Condition  Circular Wait
  • 20.
    Click to editMaster title style 20 20 Deadlock can be avoided if certain information about processes are available to the operating system before allocation of resources. For every resource request, the system sees whether granting the request will cause the system to enter an unsafe state that means this state could result in deadlock. The system then only grants the requests that will lead to safe states. Deadlock Avoidance
  • 21.
    Click to editMaster title style 2121 Deadlock Avoidance
  • 22.
    Click to editMaster title style 22 22 Deadlock Avoidance
  • 23.
    Click to editMaster title style 2323 Deadlock Avoidance
  • 24.
    Click to editMaster title style 24 24 Deadlock Detection Allow System to enter deadlock state Detection algorithm Recovery Scheme
  • 25.
    Click to editMaster title style 25 25 Deadlock Detection
  • 26.
    Click to editMaster title style 26 26 Deadlock Detection Example for Detection Algorithm
  • 27.
    Click to editMaster title style 2727 Deadlock Detection
  • 28.
    Click to editMaster title style 28 28 Deadlock Detection Once Deadlock has been detected, Some Strategy is needed for recovery. The various approaches of recovering from deadlocks are: • Process Termination • Resource Preemption
  • 29.
    Click to editMaster title style 29 29 Deadlock Recovery Process termination occurs when the process is terminated The exit() system call is used by most operating systems for process termination. This process leaves the processor and releases all its resources.
  • 30.
    Click to editMaster title style 3030 Deadlock Recovery
  • 31.
    Click to editMaster title style 31 Deadlocks-Concept Overview 31 Beyond the concepts of Deadlocks, It was very easy to understand with Realtime concepts where the resources has been allocated to the processors while performing operations in Operating System. We must ensure that the recovery Strategies of deadlocks and prevention, avoidance Algorithms well by giving suitable examples.
  • 32.
    Click to editMaster title style 32 “ Knowledge Increases by Sharing but not by Saving ” - Venkata Sreeram 18U91A584 32
  • 33.
    Click to editMaster title style 33 😁Thank you !