0% found this document useful (0 votes)
0 views

4

The document provides an overview of deadlocks in operating systems, defining deadlock and outlining necessary conditions for its occurrence. It discusses resource allocation graphs, deadlock handling methods such as prevention, avoidance, detection, and recovery, and explains concepts like safe states and deadlock recovery techniques. Additionally, it includes examples and references for further reading on operating system concepts.

Uploaded by

siddhu2004y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

4

The document provides an overview of deadlocks in operating systems, defining deadlock and outlining necessary conditions for its occurrence. It discusses resource allocation graphs, deadlock handling methods such as prevention, avoidance, detection, and recovery, and explains concepts like safe states and deadlock recovery techniques. Additionally, it includes examples and references for further reading on operating system concepts.

Uploaded by

siddhu2004y
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Operating System

CHAPTER-1
Deadlocks
Deadlock Definition
Deadlock:
•In a multiprogramming system, several process compete for limited
number of resources and if resource is not available at that
instance then process enters waiting state
•If a process is unable to change its waiting state indefinitely
because the resources requested by it are held by another waiting
process, then system is said to be in deadlock.
•OR
•If a two or more process are waiting on happening some event,
which never happed then we say these process core involved
deadlock then that state is called deadlock.
Example: Bridge Crossing

•Assume traffic in all four direction


•Each section of the bridge is viewed as a resource.
•If a deadlock occurs, it can be resolved only if one car backs up
(pre-empt resources and rollback).
•Several cars may have to be backed up if a deadlock occurs.
•Starvation is possible
System Model
• It is three step model
i. Every process will request for the resource
ii. If entertained, then process will use the resource
iii. Process must release the resource after use
Necessary and sufficient conditions for Deadlock
• There are 4 necessary and sufficient conditions for deadlock to
occur
❖ Mutual Exclusion: Atleast one resource type in the system which
can be used in non sharable mode i.e., mutual exclusion(one at a
time/ one by one). Example: Printer OR
Not sharable, Only one process can we recourses at a Time.

❖ Hold & Wait: A process is currently holding at least one resource


and requesting additional resources which are being held by
other processes.
Necessary and sufficient conditions for Deadlock cont…
❖ No pre-emption: A resource cannot be pre-empted that is a
resource will be released by the process after completion of its
task, voluntarily,

❖ Circular Wait: Each process must be waiting for a resource which


is being held by another process, which in turn is waiting for the
first process to release the resource.
Resource-Allocation Graph
• In some cases deadlocks can be understood more clearly
using Resource-Allocation Graphs, having the following
properties:
• A set of resource categories, { R1, R2, R3, . . ., RN }, which appear
as square nodes on the graph. Dots inside the resource nodes
indicate specific instances of the resource. ( E.g. two dots might
represent two laser printers. )
• A set of processes, { P1, P2, P3, . . ., PN }
• Request Edges - A set of directed arcs from Pi to Rj, indicating
that process Pi has requested Rj, and is currently waiting for that
resource to become available.
Resource-Allocation Graph
• Assignment Edges - A set of directed arcs from Rj to Pi indicating
that resource Rj has been allocated to process Pi, and that Pi is
currently holding resource Rj.
• Note that a request edge can be converted into an assignment
edge by reversing the direction of the arc when the request is
granted.
Example
• If a resource-allocation graph contains no
cycles, then the system is not deadlocked.
( When looking for cycles, remember that
these are directed graphs. )
• If a resource-allocation graph does
contain cycles AND each resource
category contains only a single instance,
then a deadlock exists.
• If a resource category contains more than
one instance, then the presence of a cycle
in the resource-allocation graph indicates
the possibility of a deadlock but does not Fig: Resource allocation graph

guarantee one
Example

Fig: Resource allocation graph with a deadlock Fig: Resource allocation graph with a cycle but no deadlock
Deadlock handling methods
• Prevention: it means to design such a system which violate
atleast one of the four necessary condition of deadlock and
ensure that deadlock should not occur.
• Avoidance: System maintains a set of data using which it takes a
decision whether to entertain a new request or not, to be in safe
state.
• Detection & recovery: In this we wait untill the deadlock occurs
and once we detect it, we recover from it.
• Ignorance: We ignore the problem as if it does not exist.
Deadlock Prevention

Mutual Exclusion:
• If a resource is assigned to more than one process, i.e., if a
resource is made sharable then deadlock will not occur

• However based on hardware some resources cannot be shared


among several processes at a time. For example: Printer, CD
recorder, etc…

• So this prevention technique is not feasible.


Deadlock Prevention
Hold & Wait:
• Conservative approach: Process is allowed to start execution if
and only if it has acquired all the resources(less efficient, not
implementable, easy, deadlock independence).
• Do not hold: Process will acquire only desired resources, but
before making any fresh request it must release all the resources
that is currently held. (efficient, implementable).
• Wait timeouts: We place a maximum time upto which a process
can wait. After which process must release all the holding
resources.
Deadlock Prevention
No pre-emption:
• Forcefull pre-emption: We allow a process to forcefully
pre-empt the resource holding by other processes.
• This method may be used by high priority process or system
process.
• The process which are in waiting state must be selected as a
victim instead of process in the running state.
Deadlock Prevention
Circular wait:
• Circular wait can be eliminated by just giving a natural number
to every resource
f:N->R
• Allow every process to make request either only in the
increasing or decreasing order of the resource number.
• If a process require a resource of lesser number (in case of
increasing order), than it must first release all the resources
larger than required number.
Deadlock Avoidance
• The general idea behind deadlock avoidance is to prevent
deadlocks from ever happening, by preventing at least one of the
aforementioned conditions.
• This requires more information about each process, AND tends
to lead to low device utilization. ( i.e. it is a conservative
approach).
• In some algorithms the scheduler only needs to know
the maximum number of each resource that a process might
potentially use. In more complex algorithms the scheduler can
also take advantage of the schedule of exactly what resources
may be needed in what order.
Deadlock Avoidance
• When a scheduler sees that starting a process or granting
resource requests may lead to future deadlocks, then that
process is just not started or the request is not granted.
• A resource allocation state is defined by the number of available
and allocated resources, and the maximum requirements of all
processes in the system.
Safe State
• A state is safe if the system can allocate all resources requested
by all processes ( up to their stated maximums ) without entering
a deadlock state.
• More formally, a state is safe if there exists a safe sequence of
processes { P0, P1, P2, ..., PN } such that all of the resource
requests for Pi can be granted using the resources currently
allocated to Pi and all processes Pj where j < i. ( I.e. if all the
processes prior to Pi finish and free up their resources, then Pi
will be able to finish also, using the resources that they have
freed up. )
Safe State
•If a safe sequence does not exist, then
the system is in an unsafe state,
which MAY lead to deadlock. ( All safe
states are deadlock free, but not all
unsafe states lead to deadlocks. )

Fig:Safe, unsafe, and deadlocked state spaces (Source:Google)


Deadlock Detection
•If deadlocks are not avoided, then another approach is to detect
when they have occurred and recover somehow.
•In addition to the performance hit of constantly checking for
deadlocks, a policy / algorithm must be in place for recovering from
deadlocks, and there is potential for lost work when processes must
be aborted or have their resources pre-empted

Windows 10
Deadlock Recovery
• When a Deadlock Detection Algorithm determines that a
deadlock has occurred in the system, the system must recover
from that deadlock.
• There are two approaches of breaking a Deadlock:
1. Process Termination
2. Resource Pre-emption
Deadlock Recovery
1. Killing Process :
killing all process involved in deadlock.
Killing process one by one after killing each process check for
deadlock again.
2. Resource Pre-emption:
Resources are pre-empted from the process involved in
deadlock, pre-empted resources are allocated to other process so
that there is the probability of recovering the system from
deadlock.
References
[1] Silberschatz, A., Galvin, P. B., & Gagne, G. (2005). Operating system concepts.
Hoboken, NJ: J. Wiley & Sons.
[2] Stallings, W. (2018). Operating systems: Internals and design principles.
Prentice-Hall
[3] Tanenbaum, A. (2014). Modern operating systems. Harlow: Pearson.
[4] Nutt, G. J. (2004). Operating systems: A modern perspective. Boston:
Pearson/Addison Wesley.
[5] Bower T. Operating System Structure. K–State Polytechnic.
http://faculty.salina.k-state.edu/tim/ossg/Introduction/struct.html
[6] Bower T. Basic Operating System Concepts. K–State Polytechnic.
http://faculty.salina.k-state.edu/tim/ossg/Introduction/OSrole.html
www.paruluniversity.ac.in

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy