UNIT 4 OS DeadLock
UNIT 4 OS DeadLock
DEADLOCK
BY
AMANDEEP KAUR
DL-char.
Handling of DL-i.e. DL
ignorance, DL
Topics
prevention, DL
Avoidance and
Detection, DL
recovery
Starvation
Have you ever
If yes, your system was in
a DEADLOCK state.
faced any of
these problems?
PC/Laptop hanged
Mobile hanged
Deadlock
In a deadlock state a process is
unable to change its state(waiting)
indefinitely because the resources or
requested by it are being used by
another waiting process. Deadlock
State
If two or more processes are waiting
on happening of some event.
Example
Example of Deadlock: Let there be 2 processes P1 and P2 and 2
resources R1 and R2. Both P1 and P2 require Both R1 and R2 to
complete their tasks.
Mutual Exclusion (ME)
Characteristics
No Pre-emption(NP)
Hold and Wait(HW) of Dead Lock
Circular Wait(CW)
Mutual Exclusion means that
the resource can be used by Mutual
only one process at any given
point of time i.e. the resource
is non sharable. e.g. Printer. Exclusio
Two processes can not print a
document at the same time
from a printer. Hence printer is
n (1 by
a non sharable resource.
1)
No Preemption means that
none of the processes No Pre-emption(NP)
involved in the deadlock is
ready to release (preempt) (i.e.No need to pre-empt
the resource it is currently
holding. or stop the execution of
process)
Hold and Wait means that the
process must be holding at least
one resource and requesting for
Hold and
at least one resource. e.g. Process
P1 is holding resource R1 and
waiting for the resource R2.
Wait
Circular wait means A set {P0,
P1,..Pn} of waiting processes
must exist such that P0 is
waiting for a resource held by
Circular
P1, P1 waiting for resource held
by
P2, …Pn-1 is waiting for
wait
resource held by Pn and Pn
waiting for a resource held by
P0.
Resource allocation graphs are
used to describe a deadlock.
Resource allocation graph consists Resourc
of
Vertices (V) – that represent
Processes (in circle) and
e
Resources (in rectangles)
Edges (E) – Request edge (from Allocatio
n Graph
process towards resource) and
Assignment edge (from
resource towards process)
Instances of a resource are
represented by a dot(.)
(RAG)
Resource Allocation Graph
Deadlock Ignorance (Ostrich
Method) Handling
Deadlock Prevention
Deadlock Avoidance & Detection of
(Banker’s Algorithm)
Deadlock Recovery
deadlocks
Deadlock
When deadlock occurs then just
ignore it because deadlock occurs Ignorance
very rare.
For eg. Sandstorm ignore by
or Ostrich
Ostrich. Method
Prevention is better than cure.
If it false either all or any one condition then there
is no deadlock.
Deadlock
No Mutual Exclusion (resources must be sharable)
Pre-emption (pre-empt processes) or (Time Prevention
Quantum or Time Stamp used to achieve it)
No Hold and Wait (all resources must be release or
free.)
No Circular Wait (ordering of resources in
increasing order must be followed by system)
Eg.(Circular wait removed by numbering
each resources)
Deadlock avoidance uses resource allocation Deadlock
algorithms and request protocols to dynamically
allocate resources in a way that prevents the Avoidance &
system from entering a Deadlock state. The key
is to make sure that resource requests do not Detection or
lead to situations where all necessary
conditions for Deadlock are met. Banker’s
Safe and unsafe conditions are used in this Algorithm
method.
It used in Deadlock Avoidance.
It is used to detect the deadlock as well Banker’s
as to avoid the deadlock.
Detection means find the deadlock
Algorithm
whether it is occurs in future or not via
some criteria (Banker’s Algorithm).
Remaining Need=Max. Need –
Formulas
Allocation
Available Resource=Total Resources- (Banker’s Algo.)
Total Allocated Resources
Banker’s Algorithm (Deadlock Avoidance)
Max. Need: How many max. resources
are required to complete a process.
Allocate: Already how many are
allocated to process. Definitions
Available: currently available resources
(how many resources are available aka
free resources.
Banker’s Algorithm
Banker’s Algorithm used in?
A. Deadlock Avoidance
B. Deadlock Protection
C. Deadlock Detection
D. Deadlock Recovery
Ans. A
A) Deadlock Avoidance
The Banker's Algorithm is a deadlock avoidance
algorithm that dynamically checks resource
allocation requests to ensure that the system
remains in a safe state. It simulates resource
allocation for processes to see if it is possible to
satisfy all current processes without leading to a
deadlock.
Gate Que.
Q/A
Q. A single processor system has three resource types X, Y and Z,
which are shared by three processes. There are 5 units of each
resource type. Consider the following scenario, where the column
alloc denotes the number of units of each resource type allocated
to each process, and the column request denotes the number of
units of each resource type requested by a process in order to
complete execution. Which of these processes will finish LAST?
A. P0
B. P1
C. P2
D. None of the above since the system is in a deadlock
No need to calculate Remaining Time. So just find
out available resources. Create safe sequence (P2)
It is used to recover the deadlock.
Process Kill Method: When process
create problem then that process Deadlock
must be kill by system.
If a deadlock is detected in the Recovery
system, the next step is to recover
from it. There are two methods to do
so:
1. Process termination
2. Preempt resources from some of
the deadlocked processes
Process Termination. Terminate all the
deadlocked processes. Terminate Deadlock
processes one by one until the deadlock is
broken. ... Recovery
Resource preemption. In resource Methods
preemption some resources are
preempted from certain processes and
these resources can then be allocated to
other process.
Terminate all the deadlocked processes.
Terminate processes one by one until the
deadlock is broken. However, the issue is to
decide which process to terminate. Certain
factors that can be used are:
How long the process has computed?
Process
Termination
How much the process has finished its working?
What is the priority of the process?
How many resources are being used by the
process?
How many total processes will be required to be
terminated?
In resource pre-emption some
resources are pre-empted from certain
processes and these resources can
then be allocated to other process.
But, certain issues that should be
addressed are:
Select a victim – which process to Resource
select for preempting the resources.
pre-emption
Rollback – the process whose
resources are preempted, can not
continue execution. So, a process
must be rolled back to some safe
state.
Or abort the process and restart
Starvation – It must be ensured that the
same process does not get selected for
resource preemption, as this will lead to
starvation.
Starvation: When Process waiting for
resources infinite. And solution is aging. Starvation
Eg.Priority Scheduling
Livelock is a condition that occurs in
operating systems and distributed systems
or Livelock
when multiple processes or threads
become stuck in a loop and are unable to
progress despite continuing to consume
resources.
Eg. Process synchronization (procss stuck
in loop)
Aging: With the time , set the lower
priority process so that those process
will be executed and hence
starvation problem will be resolved.
Or Aging
The resource allocation priority
scheme should contain concepts
such as aging, in which the priority of
a process increases the longer it
waits. It prevents starvation.
Eg. MLFQ(Multi-Level Feedback
Queue)
Deadlock VS Starvation
Protection and Security
Need for Security
Security Vulnerability like Buffer overflow, Trapdoors, Backdoors,
cache poisoning etc,
Authentication-Password based Authentication
Password Maintenance & Secure Communication
Application Security - Virus,
Program Threats
Goals of protection
Principles of protection
Domain of protection
Access matrix
Implementation of access matrix
System and network threats
Examples of attacks
Protection VS Security
References
OPERATING SYSTEM CONCEPTS by ABRAHAM SILBERSCHATZ,
PETER B. GALVIN, GERG GAGNE, WILEY
DESIGN OF THE UNIX OPERATING SYSTEM by MAURICE J. BACH,
Pearson Education India
REAL-TIME SYSTEMS by JANE W. S. LIU, Pearson Education India
https://www.theknowledgeacademy.com/blog/deadlock-in-os/#:~:t
ext=Deadlock%20in%20OS%20refers%20to,can't%20make%20an
y%20progress
.
MCQ QUIZ
Which of the following conditions is NOT one
of the necessary conditions for a deadlock to
occur?
A) Mutual Exclusion
B) Hold and Wait
C) Preemption
D) Circular Wait
Ans. C)
C) Preemption
In which situation is a deadlock most likely to occur?
B) Banker's Algorithm
A system that detects deadlocks should
take which of the following actions?