SlideShare a Scribd company logo
1 of 32
Download to read offline
Amrita
School
of
Engineering,
Bangalore
Ms. Harika Pudugosula
Lecturer
Department of Electronics & Communication Engineering
• System Model
• Deadlock Characterization
• Methods for Handling Deadlocks
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• Recovery from Deadlock
2
Introduction
• In a multiprogramming environment, several processes may compete for a finite
number of resources
• A process requests resources; if the resources are not available at that time, the
process enters a waiting state
• Sometimes, a waiting process is never again able to change state, because the
resources it has requested are held by other waiting processes
• This situation is called a deadlock
• Although some applications can identify programs that may deadlock, operating
systems typically do not provide deadlock-prevention facilities, and it remains the
responsibility of programmers to ensure that they design deadlock-free programs
3
Objectives
• To develop a description of deadlocks, which prevent sets of concurrent processes
from completing their tasks
• To present a number of different methods for preventing or avoiding deadlocks in a
computer system
4
System Model
• A system consists of a finite number of resources to be distributed among a number
of competing processe
• The resources are partitioned into several types
• Resource types: Physical resources (CPU cycles, files, and I/O devices); Logical
resources (semaphores, mutex locks, files etc.,)
• Each type consisting of some number of identical instances. Eg., 5 instances of
printers
• If a process requests an instance of a resource type, the allocation of any instance of
the type should satisfy the request
• Synchronization tools such as mutex locks, semaphores are also considered as system
resources. These are generally used for protecting some shared data structures.
These are logical resources
5
System Model
• A process utilizes a resource in only the following sequence -
1. Request - The process requests the resource. If the request cannot be granted
immediately (for example, if the resource is being used by another process), then
the requesting process must wait until it can acquire the resource
2. Use - The process can operate on the resource (for example, if the resource is a
printer, the process can print on the printer)
3. Release - The process releases the resource
• System calls are used for request and release of resources
• request() and release() device
• open() and close() file
• allocate() and free() memory
• wait() and signal() operations on semaphore
• acquire() and release() of a mutex lock
6
• System table records whether each resource is free or allocated. For each resource
that is allocated, the table also records the process to which it is allocated
• If a process requests a resource that is currently allocated to another process, it can
be added to a queue of processes waiting for this resource
• A set of processes is in a deadlocked state when every process in the set is waiting
for an event that can be caused only by another process in the set
• Example: Two processes requires two resources to complete their task at a time
System Model
7
• In a deadlock, processes never finish executing, and system resources are tied up,
preventing other jobs from starting
Necessary Conditions
• A deadlock situation can arise if the following four conditions hold simultaneously in
a system:
• Mutual exclusion- Atleast one resource must be held in a nonsharable mode;
that is, only one process at a time can use the resource. If another process
requests that resource, the requesting process must be delayed until the
resource has been released
• Hold and wait- A process must be holding at least one resource and waiting to
acquire additional resources that are currently being held by other processes
• No preemption- Resources cannot be preempted; that is, a resource can be
released only voluntarily by the process holding it, after that process has
completed its task
Deadlock Characterization
8
Necessary Conditions
• A deadlock situation can arise if the following four conditions hold simultaneously in
a system:
• Circular wait- A set {P0, P1, ..., Pn} of waiting processes must exist such that P0 is
waiting for a resource held by P1, P1 is waiting for a resource held by P2, ...,
Pn−1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by
P0
• All four conditions must hold for a deadlock to occur
• The circular-wait condition implies the hold-and-wait condition, so the four
conditions are not completely independent
Deadlock Characterization
9
Resource Allocation Graph (RAG)
• Deadlocks can be described more precisely in terms of a directed graph called a
system resource-allocation graph
• This graph consists of a set of vertices V and a set of edges E
• The set of vertices V is partitioned into two different types of nodes:
• P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the system
• R = {R1, R2, ..., Rm}, the set consisting of all resource types in the system
• A directed edge Pi → Rj is called a request edge; a directed edge Rj → Pi is called an
assignment edge
• Each process Pi represeted as a circle and each resource type Rj as a rectangle
• If resource type Rj may have more than one instance, then represent each such
instance as a dot within the rectangle
• A request edge points to only the rectangle Rj , whereas an assignment edge must
also designate one of the dots in the rectangle
Deadlock Characterization
10
Deadlock Characterization
11
Example of a Resource Allocation Graph
Process states:
• Process P1 is holding an instance of resource type
R2 and is waiting for an instance of resource type
R1
• Process P2 is holding an instance of R1 and an
instance of R2 and is waiting for an instance of R3
• Process P3 is holding an instance of R3
12
Resource Allocation Graph (RAG)
• When the process no longer needs access to the resource, it releases the resource.
As a result, the assignment edge is deleted
• Given the definition of a resource-allocation graph, it can be shown that, if the graph
contains no cycles, then no process in the system is deadlocked
• If there is a cycle, then the system may or may not be in a deadlocked state
• If each resource type has exactly one instance, then a cycle implies that a deadlock
has occurred
• If several instances per resource type, then a cycle implies that possibility of
deadlock
Deadlock Characterization
13
Resource Allocation Graph (RAG)
• If the cycle involves only a set of resource types, each of which has only a single
instance, then a deadlock has occurred. Each process involved in the cycle is
deadlocked. In this case, a cycle in the graph is both a necessary and a sufficient
condition for the existence of deadlock
• If each resource type has several instances, then a cycle does not necessarily imply
that a deadlock has occurred. In this case, a cycle in the graph is a necessary but not
a sufficient condition for the existence of deadlock
Deadlock Characterization
14
Resource Allocation Graph (RAG)
• Graph- no cycles-no deadlock
• Graph –cycles-deadlock may or may not occurred
• Resource- one instance- if cycle- implies- deadlock occurred
• Resource- many instance- if cycle- implies- may or not deadlock occurred
• Cycle in graph-is both sufficient and necessary condition –in graph-for deadlock
• Resources-many instance-cycle in graph –is a necessary but not a sufficient
condition for the existence of deadlock
• If a resource-allocation graph does not have a cycle, then the system is not in a
deadlocked state. If there is a cycle, then the system may ormay not be in a
deadlocked state
• This observation is important when we deal with the deadlock problem
Deadlock Characterization
15
• RAG with deadlock • RAG without deadlock
P1 → R1 → P2 → R3 → P3 → R2 → P1
P2 → R3 → P3 → R2 → P2
P1 → R1 → P3 → R2 → P1
Deadlock Characterization
16
Resource Allocation Graph (RAG) - Summary
• If a resource-allocation graph does not have a cycle, then the system is not in a
deadlocked state
• If there is a cycle, then the system may or may not be in a deadlocked state. This
observation is important when we deal with the deadlock problem
Deadlock Characterization
17
• Deadlock problem can be dealed in one or three ways:
• Ensure through protocol that the system will never enter a deadlock state:
• Deadlock prevention
• Deadlock avoidance
• Allow the system to enter a deadlock state, detect it and then recover
• Ignore the problem and pretend that deadlocks never occur in the system
• The third solution is the one used by most operating systems, including Linux and
Windows
• It is then up to the application developer to write programs that handle deadlocks
• To ensure that deadlocks never occur, the system can use either a deadlock
prevention or a deadlock-avoidance scheme
Methods for Handling Deadlocks
18
• Deadlock prevention -
• Methods to ensure that at least one of the necessary conditions (Mutual
exclusion, hold&wait, No preemption and circular wait) cannot hold
• These methods prevent deadlocks by constraining how requests for resources can
be made
• Deadlock avoidance -
• Deadlock avoidance requires that the operating system be given additional
information in advance concerning which resources a process will request and use
during its lifetime
•With this additional knowledge, the operating system can decide for each request
whether or not the process should wait
•To decide whether the current request can be satisfied or must be delayed, the
system must consider the resources currently available, the resources currently
allocated to each process, and the future requests and releases of each process
Methods for Handling Deadlocks
19
• If a system does not employ either a deadlock-prevention or a deadlockavoidance
algorithm, then a deadlock situation may arise
• In this environment, the system can provide an algorithm that examines the state of
the system to determine whether a deadlock has occurred and an algorithm to
recover from the deadlock (if a deadlock has indeed occurred)
• In the absence of algorithms -
• When deadlock is occurred and it is not detected and recovered then undetected
deadlock will cause the system's performance to deteriorate
• Eventually, the system will stop functioning and will need to be restarted
manually
• A system is in a frozen state but not in a deadlocked state
Methods for Handling Deadlocks
20
• By ensuring that at least one of the four conditions( mutual exclusion, hold&wait,
no preemption and circular wait) cannot hold, an occurence of deadlock can be
prevented
• Prevention of deadlocks can be done by limiting the requests to use resources
Mutual Prevention
• A resource should be used by only one process at a time means all resources are
non-sharable
• It is not possible to share a resource by more than one process simultaneously, then
we get wrong result
• At least one resource must be nonsharable. Only nonsharable resources can involve
in a deadlock
• Example -
• Sharable resource - Read-only file
• Nonsharable resource - mutex lock, cannot prevent deadlocks by denying the
mutual-exclusion condition
Deadlock Prevention
21
• By ensuring that at least one of the four conditions( mutual exclusion, hold&wait,
no preemption and circular wait) cannot hold, an occurence of deadlock can be
prevented
• Prevention of deadlocks can be done by limiting the requests to use resources
Mutual Prevention
• A resource should be used by only one process at a time means all resources are
non-sharable
• It is not possible to share a resource by more than one process simultaneously, then
we get wrong result
• At least one resource must be nonsharable. Only nonsharable resources can involve
in a deadlock
• Example -
• Sharable resource - Read-only file
• Nonsharable resource - mutex lock, cannot prevent deadlocks by denying the
mutual-exclusion condition
Deadlock Prevention
22
• A process is holding some resource and waiting for other resource
• Consider example 2 process and 2 resources
• P1 is holding r1 and is waiting for r2
• P2 is holding r2 and is waiting for r1
• This situation is called hold and wait
• To ensure that the hold-and-wait condition never occurs in the system, then the
system must guarantee that, whenever a process requests a resource, it does not
hold any other resources
• Protocol1
• Each process has to request and be allocated all its resources before it begins
execution
• Example
• Let process require 5 resources-put request-once get all resources-start
execution
• Only wait no hold here
Hold and Wait
23
• Protocol 2
• A process has to request resources only when it has none
• A process may request some resources and use them
• Before it can request any additional resources, it must release all the resources
that it is currently allocated
Difference between Protocol 1 and Protocol 2 -
• Consider a process that copies data from a DVD drive to a file on disk, sorts the file,
and then prints the results to a printer
• Protocol1 -
• If all resources must be requested at the beginning of the process, then the
process must initially request the DVD drive, disk file, and printer
• It will hold the printer for its entire execution, even though it needs the printer
only at the end
Hold and Wait
24
• Protocol2 -
• Allows the process to request initially only the DVD drive and disk file
• Copies from the DVD drive to the disk and then releases both the DVD drive and
the disk file
• The process must then request the disk file and the printer
• After copying the disk file to the printer, it releases these two resources and
terminates
• Disadvantages with both the protocols -
1) Low resource utilization
2) Starvation
Hold and Wait
25
• If a process that is holding some resources requests another resource that cannot be
immediately allocated to it, then all resources currently being held are released
• Preempted resources are added to the list of resources for which the process is
waiting
• Process will be restarted only when it can regain its old resources, as well as the new
ones that it is requesting
• Alternative -
• P1 requests a resource R1, if R1 is available then it is allotted to P1
• Otherwise, check whether R1 is allotted to some other process which is waiting for
additional resources
• If so, preempt the desired resources from the waiting process and allocate them to
the requesting process
• If the resources are not held by a waiting process, the requesting process must wait
No Preemption
26
• While it is waiting, some of its resources may be preempted, but only if another
process requests them
• A process can be restarted only when it is allocated the new resources it is
requesting and recovers any resources that were preempted while it was waiting
• This protocol is often applied to resources whose state can be easily saved and
restored later, such as CPU registers and memory space
• It cannot generally be applied to such resources as mutex locks and semaphores
• A process cannot release a resource until and unless it has completed execution
• Example
• P1 r1 p2
• Whenever p1 request for resource r1, OS finds it is allocated to p2
• OS checks does p1 has acquired any other resources, then it will release those
resources. This is first solution
No Preemption
27
• Example
• P1 r1 p2 r2
• Os knows p2 is waiting for r2 so it release r1
• P1 r1 p2 r2
• This is second solution
No Preemption
28
• To ensure circular wait doesn't occur, we impose a total ordering of all resource
types and we require that each process requests resources in an increasing order of
enumeration.
• To illustrate,
• Let R = {R1, R2, ..., Rm} be the set of resource types. We assign to each resource
type a unique integer number, which allows us to compare two resources and to
determine whether one precedes another in our ordering.
• Let’s define a one-to-one function F: R → N, where N is the set of natural
numbers.
• For example, if the set of resource types R includes tape drives, disk drives, and
printers, then the function F might be defined as follows:
• F (tape drive) = 1
• F (disk drive) = 5
• F (printer) = 12
• Protocol - Each process can request resources only in an increasing order of
enumeration
Circular Wait
29
• A process can initially request any number of instances of a resource type — say, Ri
• After that, the process can request instances of resource type Rj if and only if
F(Rj) > F(Ri)
• For example, using the function defined previously, a process that wants to use the
tape drive and printer at the same time must first request the tape drive and then
request the printer
• Alternatively, one can require that a process requesting an instance of resource type
Rj must have released any resources Ri such that F(Ri) ≥ F(Rj)
Circular Wait
30
31
References
1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition,
John Wiley and Sons, 2012.
32
Thank you

More Related Content

Similar to Deadlocks Part- I.pdf

Similar to Deadlocks Part- I.pdf (20)

OS 7.pptx
OS 7.pptxOS 7.pptx
OS 7.pptx
 
Deadlock
DeadlockDeadlock
Deadlock
 
OS deadlock.pptx
OS deadlock.pptxOS deadlock.pptx
OS deadlock.pptx
 
Deadlocks2
Deadlocks2Deadlocks2
Deadlocks2
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt3 (1) [Autosaved].ppt
3 (1) [Autosaved].ppt
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
chapter06-new.pptx
chapter06-new.pptxchapter06-new.pptx
chapter06-new.pptx
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Ch7 deadlocks
Ch7   deadlocksCh7   deadlocks
Ch7 deadlocks
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
deadlock part5 unit 2.ppt
deadlock part5 unit 2.pptdeadlock part5 unit 2.ppt
deadlock part5 unit 2.ppt
 
CPU SCHEDULING AND DEADLOCK
CPU SCHEDULING AND	DEADLOCKCPU SCHEDULING AND	DEADLOCK
CPU SCHEDULING AND DEADLOCK
 

More from Harika Pudugosula

Artificial Neural Networks_Part-2.pptx
Artificial Neural Networks_Part-2.pptxArtificial Neural Networks_Part-2.pptx
Artificial Neural Networks_Part-2.pptxHarika Pudugosula
 
Artificial Neural Networks_Part-1.pptx
Artificial Neural Networks_Part-1.pptxArtificial Neural Networks_Part-1.pptx
Artificial Neural Networks_Part-1.pptxHarika Pudugosula
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfHarika Pudugosula
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfHarika Pudugosula
 
Multithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfMultithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfHarika Pudugosula
 
Memory Management Strategies - IV.pdf
Memory Management Strategies - IV.pdfMemory Management Strategies - IV.pdf
Memory Management Strategies - IV.pdfHarika Pudugosula
 
Memory Management Strategies - III.pdf
Memory Management Strategies - III.pdfMemory Management Strategies - III.pdf
Memory Management Strategies - III.pdfHarika Pudugosula
 
Memory Management Strategies - II.pdf
Memory Management Strategies - II.pdfMemory Management Strategies - II.pdf
Memory Management Strategies - II.pdfHarika Pudugosula
 
Memory Management Strategies - I.pdf
Memory Management Strategies - I.pdfMemory Management Strategies - I.pdf
Memory Management Strategies - I.pdfHarika Pudugosula
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfHarika Pudugosula
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfHarika Pudugosula
 
Operating System Structure Part-II.pdf
Operating System Structure Part-II.pdfOperating System Structure Part-II.pdf
Operating System Structure Part-II.pdfHarika Pudugosula
 
Operating System Structure Part-I.pdf
Operating System Structure Part-I.pdfOperating System Structure Part-I.pdf
Operating System Structure Part-I.pdfHarika Pudugosula
 
Lecture-4_Process Management.pdf
Lecture-4_Process Management.pdfLecture-4_Process Management.pdf
Lecture-4_Process Management.pdfHarika Pudugosula
 
Lecture_3-Process Management.pdf
Lecture_3-Process Management.pdfLecture_3-Process Management.pdf
Lecture_3-Process Management.pdfHarika Pudugosula
 

More from Harika Pudugosula (20)

Artificial Neural Networks_Part-2.pptx
Artificial Neural Networks_Part-2.pptxArtificial Neural Networks_Part-2.pptx
Artificial Neural Networks_Part-2.pptx
 
Artificial Neural Networks_Part-1.pptx
Artificial Neural Networks_Part-1.pptxArtificial Neural Networks_Part-1.pptx
Artificial Neural Networks_Part-1.pptx
 
Introduction.pptx
Introduction.pptxIntroduction.pptx
Introduction.pptx
 
CPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdfCPU Scheduling Part-III.pdf
CPU Scheduling Part-III.pdf
 
CPU Scheduling Part-II.pdf
CPU Scheduling Part-II.pdfCPU Scheduling Part-II.pdf
CPU Scheduling Part-II.pdf
 
CPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdfCPU Scheduling Part-I.pdf
CPU Scheduling Part-I.pdf
 
Multithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdfMultithreaded Programming Part- III.pdf
Multithreaded Programming Part- III.pdf
 
Multithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdfMultithreaded Programming Part- II.pdf
Multithreaded Programming Part- II.pdf
 
Multithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdfMultithreaded Programming Part- I.pdf
Multithreaded Programming Part- I.pdf
 
Deadlocks Part- II.pdf
Deadlocks Part- II.pdfDeadlocks Part- II.pdf
Deadlocks Part- II.pdf
 
Memory Management Strategies - IV.pdf
Memory Management Strategies - IV.pdfMemory Management Strategies - IV.pdf
Memory Management Strategies - IV.pdf
 
Memory Management Strategies - III.pdf
Memory Management Strategies - III.pdfMemory Management Strategies - III.pdf
Memory Management Strategies - III.pdf
 
Memory Management Strategies - II.pdf
Memory Management Strategies - II.pdfMemory Management Strategies - II.pdf
Memory Management Strategies - II.pdf
 
Memory Management Strategies - I.pdf
Memory Management Strategies - I.pdfMemory Management Strategies - I.pdf
Memory Management Strategies - I.pdf
 
Virtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdfVirtual Memory Management Part - II.pdf
Virtual Memory Management Part - II.pdf
 
Virtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdfVirtual Memory Management Part - I.pdf
Virtual Memory Management Part - I.pdf
 
Operating System Structure Part-II.pdf
Operating System Structure Part-II.pdfOperating System Structure Part-II.pdf
Operating System Structure Part-II.pdf
 
Operating System Structure Part-I.pdf
Operating System Structure Part-I.pdfOperating System Structure Part-I.pdf
Operating System Structure Part-I.pdf
 
Lecture-4_Process Management.pdf
Lecture-4_Process Management.pdfLecture-4_Process Management.pdf
Lecture-4_Process Management.pdf
 
Lecture_3-Process Management.pdf
Lecture_3-Process Management.pdfLecture_3-Process Management.pdf
Lecture_3-Process Management.pdf
 

Recently uploaded

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 

Recently uploaded (20)

Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 

Deadlocks Part- I.pdf

  • 2. • System Model • Deadlock Characterization • Methods for Handling Deadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock 2
  • 3. Introduction • In a multiprogramming environment, several processes may compete for a finite number of resources • A process requests resources; if the resources are not available at that time, the process enters a waiting state • Sometimes, a waiting process is never again able to change state, because the resources it has requested are held by other waiting processes • This situation is called a deadlock • Although some applications can identify programs that may deadlock, operating systems typically do not provide deadlock-prevention facilities, and it remains the responsibility of programmers to ensure that they design deadlock-free programs 3
  • 4. Objectives • To develop a description of deadlocks, which prevent sets of concurrent processes from completing their tasks • To present a number of different methods for preventing or avoiding deadlocks in a computer system 4
  • 5. System Model • A system consists of a finite number of resources to be distributed among a number of competing processe • The resources are partitioned into several types • Resource types: Physical resources (CPU cycles, files, and I/O devices); Logical resources (semaphores, mutex locks, files etc.,) • Each type consisting of some number of identical instances. Eg., 5 instances of printers • If a process requests an instance of a resource type, the allocation of any instance of the type should satisfy the request • Synchronization tools such as mutex locks, semaphores are also considered as system resources. These are generally used for protecting some shared data structures. These are logical resources 5
  • 6. System Model • A process utilizes a resource in only the following sequence - 1. Request - The process requests the resource. If the request cannot be granted immediately (for example, if the resource is being used by another process), then the requesting process must wait until it can acquire the resource 2. Use - The process can operate on the resource (for example, if the resource is a printer, the process can print on the printer) 3. Release - The process releases the resource • System calls are used for request and release of resources • request() and release() device • open() and close() file • allocate() and free() memory • wait() and signal() operations on semaphore • acquire() and release() of a mutex lock 6
  • 7. • System table records whether each resource is free or allocated. For each resource that is allocated, the table also records the process to which it is allocated • If a process requests a resource that is currently allocated to another process, it can be added to a queue of processes waiting for this resource • A set of processes is in a deadlocked state when every process in the set is waiting for an event that can be caused only by another process in the set • Example: Two processes requires two resources to complete their task at a time System Model 7
  • 8. • In a deadlock, processes never finish executing, and system resources are tied up, preventing other jobs from starting Necessary Conditions • A deadlock situation can arise if the following four conditions hold simultaneously in a system: • Mutual exclusion- Atleast one resource must be held in a nonsharable mode; that is, only one process at a time can use the resource. If another process requests that resource, the requesting process must be delayed until the resource has been released • Hold and wait- A process must be holding at least one resource and waiting to acquire additional resources that are currently being held by other processes • No preemption- Resources cannot be preempted; that is, a resource can be released only voluntarily by the process holding it, after that process has completed its task Deadlock Characterization 8
  • 9. Necessary Conditions • A deadlock situation can arise if the following four conditions hold simultaneously in a system: • Circular wait- A set {P0, P1, ..., Pn} of waiting processes must exist such that P0 is waiting for a resource held by P1, P1 is waiting for a resource held by P2, ..., Pn−1 is waiting for a resource held by Pn, and Pn is waiting for a resource held by P0 • All four conditions must hold for a deadlock to occur • The circular-wait condition implies the hold-and-wait condition, so the four conditions are not completely independent Deadlock Characterization 9
  • 10. Resource Allocation Graph (RAG) • Deadlocks can be described more precisely in terms of a directed graph called a system resource-allocation graph • This graph consists of a set of vertices V and a set of edges E • The set of vertices V is partitioned into two different types of nodes: • P = {P1, P2, ..., Pn}, the set consisting of all the active processes in the system • R = {R1, R2, ..., Rm}, the set consisting of all resource types in the system • A directed edge Pi → Rj is called a request edge; a directed edge Rj → Pi is called an assignment edge • Each process Pi represeted as a circle and each resource type Rj as a rectangle • If resource type Rj may have more than one instance, then represent each such instance as a dot within the rectangle • A request edge points to only the rectangle Rj , whereas an assignment edge must also designate one of the dots in the rectangle Deadlock Characterization 10
  • 12. Example of a Resource Allocation Graph Process states: • Process P1 is holding an instance of resource type R2 and is waiting for an instance of resource type R1 • Process P2 is holding an instance of R1 and an instance of R2 and is waiting for an instance of R3 • Process P3 is holding an instance of R3 12
  • 13. Resource Allocation Graph (RAG) • When the process no longer needs access to the resource, it releases the resource. As a result, the assignment edge is deleted • Given the definition of a resource-allocation graph, it can be shown that, if the graph contains no cycles, then no process in the system is deadlocked • If there is a cycle, then the system may or may not be in a deadlocked state • If each resource type has exactly one instance, then a cycle implies that a deadlock has occurred • If several instances per resource type, then a cycle implies that possibility of deadlock Deadlock Characterization 13
  • 14. Resource Allocation Graph (RAG) • If the cycle involves only a set of resource types, each of which has only a single instance, then a deadlock has occurred. Each process involved in the cycle is deadlocked. In this case, a cycle in the graph is both a necessary and a sufficient condition for the existence of deadlock • If each resource type has several instances, then a cycle does not necessarily imply that a deadlock has occurred. In this case, a cycle in the graph is a necessary but not a sufficient condition for the existence of deadlock Deadlock Characterization 14
  • 15. Resource Allocation Graph (RAG) • Graph- no cycles-no deadlock • Graph –cycles-deadlock may or may not occurred • Resource- one instance- if cycle- implies- deadlock occurred • Resource- many instance- if cycle- implies- may or not deadlock occurred • Cycle in graph-is both sufficient and necessary condition –in graph-for deadlock • Resources-many instance-cycle in graph –is a necessary but not a sufficient condition for the existence of deadlock • If a resource-allocation graph does not have a cycle, then the system is not in a deadlocked state. If there is a cycle, then the system may ormay not be in a deadlocked state • This observation is important when we deal with the deadlock problem Deadlock Characterization 15
  • 16. • RAG with deadlock • RAG without deadlock P1 → R1 → P2 → R3 → P3 → R2 → P1 P2 → R3 → P3 → R2 → P2 P1 → R1 → P3 → R2 → P1 Deadlock Characterization 16
  • 17. Resource Allocation Graph (RAG) - Summary • If a resource-allocation graph does not have a cycle, then the system is not in a deadlocked state • If there is a cycle, then the system may or may not be in a deadlocked state. This observation is important when we deal with the deadlock problem Deadlock Characterization 17
  • 18. • Deadlock problem can be dealed in one or three ways: • Ensure through protocol that the system will never enter a deadlock state: • Deadlock prevention • Deadlock avoidance • Allow the system to enter a deadlock state, detect it and then recover • Ignore the problem and pretend that deadlocks never occur in the system • The third solution is the one used by most operating systems, including Linux and Windows • It is then up to the application developer to write programs that handle deadlocks • To ensure that deadlocks never occur, the system can use either a deadlock prevention or a deadlock-avoidance scheme Methods for Handling Deadlocks 18
  • 19. • Deadlock prevention - • Methods to ensure that at least one of the necessary conditions (Mutual exclusion, hold&wait, No preemption and circular wait) cannot hold • These methods prevent deadlocks by constraining how requests for resources can be made • Deadlock avoidance - • Deadlock avoidance requires that the operating system be given additional information in advance concerning which resources a process will request and use during its lifetime •With this additional knowledge, the operating system can decide for each request whether or not the process should wait •To decide whether the current request can be satisfied or must be delayed, the system must consider the resources currently available, the resources currently allocated to each process, and the future requests and releases of each process Methods for Handling Deadlocks 19
  • 20. • If a system does not employ either a deadlock-prevention or a deadlockavoidance algorithm, then a deadlock situation may arise • In this environment, the system can provide an algorithm that examines the state of the system to determine whether a deadlock has occurred and an algorithm to recover from the deadlock (if a deadlock has indeed occurred) • In the absence of algorithms - • When deadlock is occurred and it is not detected and recovered then undetected deadlock will cause the system's performance to deteriorate • Eventually, the system will stop functioning and will need to be restarted manually • A system is in a frozen state but not in a deadlocked state Methods for Handling Deadlocks 20
  • 21. • By ensuring that at least one of the four conditions( mutual exclusion, hold&wait, no preemption and circular wait) cannot hold, an occurence of deadlock can be prevented • Prevention of deadlocks can be done by limiting the requests to use resources Mutual Prevention • A resource should be used by only one process at a time means all resources are non-sharable • It is not possible to share a resource by more than one process simultaneously, then we get wrong result • At least one resource must be nonsharable. Only nonsharable resources can involve in a deadlock • Example - • Sharable resource - Read-only file • Nonsharable resource - mutex lock, cannot prevent deadlocks by denying the mutual-exclusion condition Deadlock Prevention 21
  • 22. • By ensuring that at least one of the four conditions( mutual exclusion, hold&wait, no preemption and circular wait) cannot hold, an occurence of deadlock can be prevented • Prevention of deadlocks can be done by limiting the requests to use resources Mutual Prevention • A resource should be used by only one process at a time means all resources are non-sharable • It is not possible to share a resource by more than one process simultaneously, then we get wrong result • At least one resource must be nonsharable. Only nonsharable resources can involve in a deadlock • Example - • Sharable resource - Read-only file • Nonsharable resource - mutex lock, cannot prevent deadlocks by denying the mutual-exclusion condition Deadlock Prevention 22
  • 23. • A process is holding some resource and waiting for other resource • Consider example 2 process and 2 resources • P1 is holding r1 and is waiting for r2 • P2 is holding r2 and is waiting for r1 • This situation is called hold and wait • To ensure that the hold-and-wait condition never occurs in the system, then the system must guarantee that, whenever a process requests a resource, it does not hold any other resources • Protocol1 • Each process has to request and be allocated all its resources before it begins execution • Example • Let process require 5 resources-put request-once get all resources-start execution • Only wait no hold here Hold and Wait 23
  • 24. • Protocol 2 • A process has to request resources only when it has none • A process may request some resources and use them • Before it can request any additional resources, it must release all the resources that it is currently allocated Difference between Protocol 1 and Protocol 2 - • Consider a process that copies data from a DVD drive to a file on disk, sorts the file, and then prints the results to a printer • Protocol1 - • If all resources must be requested at the beginning of the process, then the process must initially request the DVD drive, disk file, and printer • It will hold the printer for its entire execution, even though it needs the printer only at the end Hold and Wait 24
  • 25. • Protocol2 - • Allows the process to request initially only the DVD drive and disk file • Copies from the DVD drive to the disk and then releases both the DVD drive and the disk file • The process must then request the disk file and the printer • After copying the disk file to the printer, it releases these two resources and terminates • Disadvantages with both the protocols - 1) Low resource utilization 2) Starvation Hold and Wait 25
  • 26. • If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released • Preempted resources are added to the list of resources for which the process is waiting • Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting • Alternative - • P1 requests a resource R1, if R1 is available then it is allotted to P1 • Otherwise, check whether R1 is allotted to some other process which is waiting for additional resources • If so, preempt the desired resources from the waiting process and allocate them to the requesting process • If the resources are not held by a waiting process, the requesting process must wait No Preemption 26
  • 27. • While it is waiting, some of its resources may be preempted, but only if another process requests them • A process can be restarted only when it is allocated the new resources it is requesting and recovers any resources that were preempted while it was waiting • This protocol is often applied to resources whose state can be easily saved and restored later, such as CPU registers and memory space • It cannot generally be applied to such resources as mutex locks and semaphores • A process cannot release a resource until and unless it has completed execution • Example • P1 r1 p2 • Whenever p1 request for resource r1, OS finds it is allocated to p2 • OS checks does p1 has acquired any other resources, then it will release those resources. This is first solution No Preemption 27
  • 28. • Example • P1 r1 p2 r2 • Os knows p2 is waiting for r2 so it release r1 • P1 r1 p2 r2 • This is second solution No Preemption 28
  • 29. • To ensure circular wait doesn't occur, we impose a total ordering of all resource types and we require that each process requests resources in an increasing order of enumeration. • To illustrate, • Let R = {R1, R2, ..., Rm} be the set of resource types. We assign to each resource type a unique integer number, which allows us to compare two resources and to determine whether one precedes another in our ordering. • Let’s define a one-to-one function F: R → N, where N is the set of natural numbers. • For example, if the set of resource types R includes tape drives, disk drives, and printers, then the function F might be defined as follows: • F (tape drive) = 1 • F (disk drive) = 5 • F (printer) = 12 • Protocol - Each process can request resources only in an increasing order of enumeration Circular Wait 29
  • 30. • A process can initially request any number of instances of a resource type — say, Ri • After that, the process can request instances of resource type Rj if and only if F(Rj) > F(Ri) • For example, using the function defined previously, a process that wants to use the tape drive and printer at the same time must first request the tape drive and then request the printer • Alternatively, one can require that a process requesting an instance of resource type Rj must have released any resources Ri such that F(Ri) ≥ F(Rj) Circular Wait 30
  • 31. 31 References 1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition, John Wiley and Sons, 2012.