Professional Documents
Culture Documents
Instructed By
Engr. M. Asif Shaikh
Lecture 7
DEADLOCK in OS
1
A process in operating systems uses different
resources and uses resources in the following
way.
1) Requests a resource
2) Use the resource
2) Releases the resource
2
What is Deadlock?
3
Deadlock is a situation that occurs in OS
when any process enters a waiting state
because another waiting process is holding
the demanded resource.
4
Deadlock is a common problem in multi-
processing where several processes share a
specific type of mutually exclusive resource
known as a soft lock or software.
5
Example of Deadlock
6
7
A similar situation occurs in operating
systems when there are two or more
processes that hold some resources and wait
for resources held by other(s). For example,
in the below diagram, Process 1 is holding
Resource 1 and waiting for resource 2 which
is acquired by process 2, and process 2 is
waiting for resource 1.
8
9
What is Circular wait?
10
For example, Process A is allocated Resource
B as it is requesting Resource A.
11
Example of Circular wait
12
13
Avoidance Algorithms
The deadlock-avoidance algorithm helps you
14
Deadlock Conditions
Deadlock can arise if the following four
conditions hold simultaneously (Necessary
Conditions)
15
No preemptive action:
No Preemption - A resource can be released
16
The process will be restarted only if it can
regain its old resource and a new one that it
is requesting.
If the process is requesting some other
17
Mutual Exclusion:
Mutual Exclusion is a full form of Mutex.
It is a special type of binary semaphore which
19
Hold and Wait:
In this condition, processes must be stopped
20
Circular Wait:
It imposes a total ordering of all resource
types.
Circular wait also requires that every process
21
Methods for handling deadlock
22
1. Deadlock Avoidance
It is better to avoid a deadlock instead of
taking action after the Deadlock has occurred.
resource scheduler.
25
4. Ignore the problem altogether
26
Advantages of Deadlock
Here, are pros/benefits of using Deadlock
method
This situation works well for processes which
27
Feasible to enforce via compile-time checks
28
Disadvantages of Deadlock method
Here, are cons/ drawback of using deadlock
method
Delays process initiation
Processes must know future resource need
Pre-empts more often than necessary
Dis-allows incremental resource requests
Inherent preemption losses.
29
Difference Between Starvation and Deadlock
30
31