SlideShare a Scribd company logo
1 of 19
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
Deadlock Detection
• If a system does not employ either a deadlock-prevention or a deadlock avoidance
algorithm, then a deadlock situation may occur
• In this environment, the system may provide -
• An algorithm that examines the state of the system to determine whether a
deadlock has occurred
• An algorithm to recover from the deadlock
• Two requirements as they pertain to systems with only a single instance of each
resource type, systems with several instances of each resource type
• Includes not only the run-time costs of maintaining the necessary information and
executing the detection algorithm but also the potential losses inherent in
recovering from a deadlock
3
Single Instance of Each Resource Type
• If all resources have only a single instance, then we can define a deadlock detection
algorithm that uses a variant of the resource-allocation graph - Wait-for graph
• Graph obtained from the resource-allocation graph by removing the resource nodes
and collapsing the appropriate edge
• An edge from Pi to Pj in a wait-for graph implies that process Pi is waiting for
process Pj to release a resource that Pi needs
• An edge Pi → Pj exists in a wait-for graph if and only if the corresponding resource
allocation graph contains two edges Pi → Rq and Rq → Pj for some resource Rq
• A deadlock exists in the system if and only if the wait-for graph contains a cycle
• To detect deadlocks, the system needs to maintain the wait-for graph and periodically
invoke an algorithm that searches for a cycle in the graph
• An algorithm to detect a cycle in a graph requires an order of n2 operations, where n
is the number of vertices in the graph
4
Single Instance of Each Resource Type
5
fig a : Resource-Allocation Graph fig b: Corresponding wait-for graph
Several Instances of a Resource Type
• The wait-for graph scheme is not applicable to a resource-allocation system with
multiple instances of each resource type
• The algorithm employs several time-varying data structures
• Available - A vector of length m indicates the number of available resources of
each type
• Allocation - An n × m matrix defines the number of resources of each type
currently allocated to each process
• Request - An n × m matrix indicates the current request of each process. If
Request[i][j] equals k, then process Pi is requesting k more instances of resource
type Rj
• Algorithm requires an order of O(m x n2) operations to detect whether the system is
in deadlocked state
6
Several Instances of a Resource Type - Deadlock Detection Algorithm
7
1. Let Work and Finish be vectors of length m and n, respectively Initialize:
(a) Work = Available
(b)For i = 1,2, …, n, if Allocationi 0, then
Finish[i] = false; otherwise, Finish[i] = true
2. Find an index i such that both:
(a)Finish[i] == false
(b) Requesti <= Work
If no such i exists, go to step 4
3. Work = Work + Allocationi
Finish[i] = true
go to step 2
4. If Finish[i] == false, for some i, 0<= i <=n, then the system is in deadlock state.
Moreover, if Finish[i] == false, then Pi is deadlocked
Example - Deadlock Detection Algorithm
8
• Consider a system with five processes P0 through P4 and three resource types A, B,
and C. Resource type A has seven instances, resource type B has two instances, and
resource type C has six instances. Suppose that, at time T0, we have the following
resource-allocation state -
• System is not in a deadlocked state
Indeed, if we execute our algorithm,
we will find that the sequence
<P0, P2, P3, P1, P4> results in
Finish[i] == true for all i
• A= 7-7=0
• B=2-2=0
• C=6-6=0
• P0
Request<=work
0 0 0 <= 0 0 0 true
Work=work+allocation 0 0 0+0 1 0= 0 1 0 finish[0]=true
P0-false P1-false P2-false P3-false P4-false
0- true
9
• P1
Request <=work
2 0 2 <= 0 1 0 false p1 has to wait
• P2
Request <=work
0 0 0 <= 0 1 0 true
work=work+allocation 0 1 0 + 3 0 3=3 1 3 finish[2]=true
• P3
Request <=work
1 0 0 <= 3 1 3 true
Work= work +allocation 3 1 3 + 2 1 1= 5 2 4 finish [3]= true
• P4
Request <=work
0 0 2 < = 5 2 4 true
Work=work+ allocation 5 2 4 + 0 0 2= 5 2 6 finish[4]=true
10
• P1
Request <= work
2 0 2 <= 5 2 6
work= work + allocation 5 2 6+2 0 0= 7 2 6
• Safe sequence <p0,p2,p3,p4,p1>
11
Example - Deadlock Detection Algorithm
12
• Consider a system with five processes P0 through P4 and three resource types A, B,
and C. Resource type A has seven instances, resource type B has two instances, and
resource type C has six instances. Suppose that, at time T0, we have the following
resource-allocation state -
• System is in a deadlocked state
ALthough, reclaiming the resources
held by process P0, the number of
available resources is not sufficient
to fulfill the requests of the other
processes.
• Thus, a deadlock exists, consisting
of processes P1, P2, P3, and P4
Detection - Algorithm Usage
13
• When, and how often, to invoke depends on:
• How often a deadlock is likely to occur?
• How many processes will be affected by deadlock when it happens?
• We can invoke the deadlock-detection algorithm every time a request for allocation
cannot be granted immediately
• Invoking the deadlock-detection algorithm for every resource request will incur
considerable overhead in computation time
• A less expensive alternative is simply to invoke the algorithm at defined intervals—
for example, once per hour or whenever CPU utilization drops below 40 percent. (A
deadlock eventually cripples system throughput and causes CPU utilization to drop)
• If the detection algorithm is invoked at arbitrary points in time, the resource graph
may contain many cycles. In this case, we generally cannot tell which of the many
deadlocked processes “caused” the deadlock.
Recovery from Deadlock
• When a detection algorithm determines that a deadlock exists, several alternatives
are available.
1. Inform the operator that a deadlock has occurred and to let the operator deal
with the deadlock manually
2. Let the system recover from the deadlock automatically
• Two options for breaking a deadlock -
• Process termination
a. abort all deadlocked process
Example - Assume 10 process in that 3 process suffer deadlock they have to be
aborted
P0=95% P1=90%, P2=88% execution completed
it has used CPU time, memory, I/O devices
it is expensive approach
14
b. To abort one process at a time until deadlock cycle is eliminated i.e circular
wait
- p0,p1,p2 suffer from deadlock
- abort p0 and apply deadlock detection algorithm to find cycle is
eliminated
- similarly apply for p1,p2
• In which order should we choose to abort the process from many processes
1. Priority of the process
2. How long process has computed, and how much longer to completion
3. Resources the process has used
4. Resources process needs to complete
5. How many processes will need to be terminated
6. Is process interactive or batch?
15
Recovery from Deadlock
Recovery from Deadlock
• Two options for breaking a deadlock -
• Resource preemption
• To eliminate deadlocks using resource preemption, we successively preempt
some resources from processes and give these resources to other processes
until the deadlock cycle is broken
• If preemption is required to deal with deadlocks, then three issues need to
be addressed
1. Selecting a victim – i.e., Which resources and which processes are to be
preempted?
• As in process termination, we must determine the order of preemption to
minimize cost
• Cost factors may include such parameters as the number of resources a
deadlocked process is holding and the amount of time the process has thus far
consumed
16
Recovery from Deadlock
2. Rollback - If we pre-empt a resource from a process, what should be done with that
process?
• Clearly, it cannot continue with its normal execution; it is missing some needed
resource. We must roll back the process to some safe state and restart it from
that state
3. Starvation -
• How do we ensure that starvation will not occur? That is, how can we guarantee
that resources will not always be pre-empted from the same process?
• Ensure that a process can be picked as a victim only a (small) finite number of
times
17
18
References
1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition,
John Wiley and Sons, 2012.
19
Thank you

More Related Content

Similar to Deadlocks Part- III.pdf

Similar to Deadlocks Part- III.pdf (20)

Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptx
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Os5
Os5Os5
Os5
 
Deadlock
DeadlockDeadlock
Deadlock
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
deadlocks.pptx
deadlocks.pptxdeadlocks.pptx
deadlocks.pptx
 
Deadlock Detection.pptx
Deadlock Detection.pptxDeadlock Detection.pptx
Deadlock Detection.pptx
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
OS-Part-06.pdf
OS-Part-06.pdfOS-Part-06.pdf
OS-Part-06.pdf
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
chapter06-new.pptx
chapter06-new.pptxchapter06-new.pptx
chapter06-new.pptx
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock
DeadlockDeadlock
Deadlock
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 

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
 
Lecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdfLecture- 2_Process Management.pdf
Lecture- 2_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
 
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
 
Lecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdfLecture- 2_Process Management.pdf
Lecture- 2_Process Management.pdf
 

Recently uploaded

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 

Recently uploaded (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
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
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 

Deadlocks Part- III.pdf

  • 2. • System Model • Deadlock Characterization • Methods for Handling Deadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock 2
  • 3. Deadlock Detection • If a system does not employ either a deadlock-prevention or a deadlock avoidance algorithm, then a deadlock situation may occur • In this environment, the system may provide - • An algorithm that examines the state of the system to determine whether a deadlock has occurred • An algorithm to recover from the deadlock • Two requirements as they pertain to systems with only a single instance of each resource type, systems with several instances of each resource type • Includes not only the run-time costs of maintaining the necessary information and executing the detection algorithm but also the potential losses inherent in recovering from a deadlock 3
  • 4. Single Instance of Each Resource Type • If all resources have only a single instance, then we can define a deadlock detection algorithm that uses a variant of the resource-allocation graph - Wait-for graph • Graph obtained from the resource-allocation graph by removing the resource nodes and collapsing the appropriate edge • An edge from Pi to Pj in a wait-for graph implies that process Pi is waiting for process Pj to release a resource that Pi needs • An edge Pi → Pj exists in a wait-for graph if and only if the corresponding resource allocation graph contains two edges Pi → Rq and Rq → Pj for some resource Rq • A deadlock exists in the system if and only if the wait-for graph contains a cycle • To detect deadlocks, the system needs to maintain the wait-for graph and periodically invoke an algorithm that searches for a cycle in the graph • An algorithm to detect a cycle in a graph requires an order of n2 operations, where n is the number of vertices in the graph 4
  • 5. Single Instance of Each Resource Type 5 fig a : Resource-Allocation Graph fig b: Corresponding wait-for graph
  • 6. Several Instances of a Resource Type • The wait-for graph scheme is not applicable to a resource-allocation system with multiple instances of each resource type • The algorithm employs several time-varying data structures • Available - A vector of length m indicates the number of available resources of each type • Allocation - An n × m matrix defines the number of resources of each type currently allocated to each process • Request - An n × m matrix indicates the current request of each process. If Request[i][j] equals k, then process Pi is requesting k more instances of resource type Rj • Algorithm requires an order of O(m x n2) operations to detect whether the system is in deadlocked state 6
  • 7. Several Instances of a Resource Type - Deadlock Detection Algorithm 7 1. Let Work and Finish be vectors of length m and n, respectively Initialize: (a) Work = Available (b)For i = 1,2, …, n, if Allocationi 0, then Finish[i] = false; otherwise, Finish[i] = true 2. Find an index i such that both: (a)Finish[i] == false (b) Requesti <= Work If no such i exists, go to step 4 3. Work = Work + Allocationi Finish[i] = true go to step 2 4. If Finish[i] == false, for some i, 0<= i <=n, then the system is in deadlock state. Moreover, if Finish[i] == false, then Pi is deadlocked
  • 8. Example - Deadlock Detection Algorithm 8 • Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has seven instances, resource type B has two instances, and resource type C has six instances. Suppose that, at time T0, we have the following resource-allocation state - • System is not in a deadlocked state Indeed, if we execute our algorithm, we will find that the sequence <P0, P2, P3, P1, P4> results in Finish[i] == true for all i
  • 9. • A= 7-7=0 • B=2-2=0 • C=6-6=0 • P0 Request<=work 0 0 0 <= 0 0 0 true Work=work+allocation 0 0 0+0 1 0= 0 1 0 finish[0]=true P0-false P1-false P2-false P3-false P4-false 0- true 9
  • 10. • P1 Request <=work 2 0 2 <= 0 1 0 false p1 has to wait • P2 Request <=work 0 0 0 <= 0 1 0 true work=work+allocation 0 1 0 + 3 0 3=3 1 3 finish[2]=true • P3 Request <=work 1 0 0 <= 3 1 3 true Work= work +allocation 3 1 3 + 2 1 1= 5 2 4 finish [3]= true • P4 Request <=work 0 0 2 < = 5 2 4 true Work=work+ allocation 5 2 4 + 0 0 2= 5 2 6 finish[4]=true 10
  • 11. • P1 Request <= work 2 0 2 <= 5 2 6 work= work + allocation 5 2 6+2 0 0= 7 2 6 • Safe sequence <p0,p2,p3,p4,p1> 11
  • 12. Example - Deadlock Detection Algorithm 12 • Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has seven instances, resource type B has two instances, and resource type C has six instances. Suppose that, at time T0, we have the following resource-allocation state - • System is in a deadlocked state ALthough, reclaiming the resources held by process P0, the number of available resources is not sufficient to fulfill the requests of the other processes. • Thus, a deadlock exists, consisting of processes P1, P2, P3, and P4
  • 13. Detection - Algorithm Usage 13 • When, and how often, to invoke depends on: • How often a deadlock is likely to occur? • How many processes will be affected by deadlock when it happens? • We can invoke the deadlock-detection algorithm every time a request for allocation cannot be granted immediately • Invoking the deadlock-detection algorithm for every resource request will incur considerable overhead in computation time • A less expensive alternative is simply to invoke the algorithm at defined intervals— for example, once per hour or whenever CPU utilization drops below 40 percent. (A deadlock eventually cripples system throughput and causes CPU utilization to drop) • If the detection algorithm is invoked at arbitrary points in time, the resource graph may contain many cycles. In this case, we generally cannot tell which of the many deadlocked processes “caused” the deadlock.
  • 14. Recovery from Deadlock • When a detection algorithm determines that a deadlock exists, several alternatives are available. 1. Inform the operator that a deadlock has occurred and to let the operator deal with the deadlock manually 2. Let the system recover from the deadlock automatically • Two options for breaking a deadlock - • Process termination a. abort all deadlocked process Example - Assume 10 process in that 3 process suffer deadlock they have to be aborted P0=95% P1=90%, P2=88% execution completed it has used CPU time, memory, I/O devices it is expensive approach 14
  • 15. b. To abort one process at a time until deadlock cycle is eliminated i.e circular wait - p0,p1,p2 suffer from deadlock - abort p0 and apply deadlock detection algorithm to find cycle is eliminated - similarly apply for p1,p2 • In which order should we choose to abort the process from many processes 1. Priority of the process 2. How long process has computed, and how much longer to completion 3. Resources the process has used 4. Resources process needs to complete 5. How many processes will need to be terminated 6. Is process interactive or batch? 15 Recovery from Deadlock
  • 16. Recovery from Deadlock • Two options for breaking a deadlock - • Resource preemption • To eliminate deadlocks using resource preemption, we successively preempt some resources from processes and give these resources to other processes until the deadlock cycle is broken • If preemption is required to deal with deadlocks, then three issues need to be addressed 1. Selecting a victim – i.e., Which resources and which processes are to be preempted? • As in process termination, we must determine the order of preemption to minimize cost • Cost factors may include such parameters as the number of resources a deadlocked process is holding and the amount of time the process has thus far consumed 16
  • 17. Recovery from Deadlock 2. Rollback - If we pre-empt a resource from a process, what should be done with that process? • Clearly, it cannot continue with its normal execution; it is missing some needed resource. We must roll back the process to some safe state and restart it from that state 3. Starvation - • How do we ensure that starvation will not occur? That is, how can we guarantee that resources will not always be pre-empted from the same process? • Ensure that a process can be picked as a victim only a (small) finite number of times 17
  • 18. 18 References 1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition, John Wiley and Sons, 2012.