SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
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
Dead Avoidance
• Possible side effects of preventing deadlocks with Deadlock prevention are -
• Low device utilization and reduced system throughput
• Deadlock avoidance requires additional information about how resources have to
be requested
• Example -
• In a system with one tape drive and one printer
• The system might need to know that process P will request first the tape drive
and then the printer before releasing both resources
• Process Q will request first the printer and then the tape drive
• With this knowledge of the complete sequence of requests and releases for each
process, the system can decide for each request whether or not the process should
wait in order to avoid a possible future deadlock
3
Dead Avoidance
• Each request requires that in making this decision, the system follows the followig
approach -
• the resources currently available,
• the resources currently allocated to each process
• the future requests and releases of each process
• Algorithms that use this approach differ in the amount and type of information
required
• The simplest and most useful model requires that each process declare the
maximum number of resources of each type that it may need
• A deadlock-avoidance algorithm dynamically examines the resource-allocation state
to ensure that a circular-wait condition can never exist
• Resource Allocation state is defined by the number of available and allocated
resources and the maximum demands of the processes
4
• A state is safe if the system can allocate resources to each process in some order and
still avoid a deadlock
• A system is in a safe state only if there exists a safe sequence
• Safe sequence: A sequence of processes <P1, P2, …, Pn> is a safe sequence for the
current allocation state if, for each Pi , the resources that Pi can still request can be
satisfied by currently available resources + resources held by all the Pj, with j < i
• In this situation,
• If the resources that Pi needs are not immediately available, then Pi can wait until
all Pj have finished
• When all Pj are finished, Pi can obtain needed resources, execute, return
allocated resources, and terminate
• When Pi terminates, Pi +1 can obtain its needed resources, and so on
• If no such sequence exists, then the system state is said to be unsafe
Safe State
5
• If a system is in unsafe state possibility of deadlock
• An unsafe state may lead to a deadlock
• In an unsafe state, the operating system cannot
prevent processes from requesting resources in such
a way that a deadlock occurs. The behavior of the
processes controls unsafe states
• Avoidance ensure that a system will never enter an
unsafe state
• If a system is in safe state no deadlocks
• As long as the state is safe, the operating system can
avoid unsafe (and deadlocked) states
Safe State
6
Safe State
7
• Resource - Allocation - Graph Algorithm
• Banker’s Algorithm
• Idea behind deadlock avoidance algorithm -
• To ensure that the system will always remain in a safe state
• Whenever a process requests a resource that is currently available, the system
must decide whether the resource can be allocated immediately or whether the
process must wait
• The request is granted only if the allocation leaves the system in a safe state
• In this scheme, if a process requests a resource that is currently available, it may
still have to wait
• Thus, resource utilization may be lower than it would be
• Single instance of a resource type
• Use a resource-allocation graph
• Multiple instances of a resource type
• Use the banker’s algorithm
Two deadlock-avoidance algorithms
8
• Claim edge - Pi -->Rj indicates that process Pi may request resource Rj at some time
in the future and it is represented by a dashed line
• Claim edge converts to request edge when a process requests a resource
• Request edge converted to an assignment edge when the resource is allocated to
the process
• When a resource is released by a process, assignment edge reconverts to a claim
edge
• Resources must be claimed a priori in the system. That is, before process Pi starts
executing, all its claim edges must already appear in the resource-allocation graph
• Suppose that process Pi requests a resource Rj
• The request can be granted only if converting the request edge to an assignment
edge does not result in the formation of a cycle in the resource allocation graph
• Here, we need a cycle detection algorithm that requires an order of n*n operations,
where n is the number of processes in the system
Resource-Allocation-Graph Algorithm
9
• If no cycle exists, then the allocation of
the resource will leave the system in a
safe state. If a cycle is found, then the
allocation will put the system in an unsafe
state. In that case, process Pi will have to
wait for its requests to be satisfied
• Consider the resource-allocation graph,
suppose that P2 requests R2
• Although R2 is currently free, cannot
allocate it to P2, since this action will
create a cycle in the graph
• A cycle, as mentioned, indicates that the
system is in an unsafe state
• If P1 requests R2, and P2 requests R1,
then a deadlock will occur
Resource-Allocation-Graph Algorithm
10
• When each resource has multiple instance then banker algorithm is used
• When a new process enters the system, it must declare the maximum number of
instances of each resource type that it may need
• Number may not exceed the total number of resources in the system
• When a user requests a set of resources, the system must determine whether the
allocation of these resources will leave the system in a safe state
• If it will, the resources are allocated; otherwise, the process must wait until some
other process releases enough resources
• When a process gets all its resources it must return them in a finite amount of time
• Data structures must be maintained to implement the banker’s algorithm, to encode
the state of the resource-allocation system
Banker’s Algorithm
11
• The following data structures are used in this algorithm
n is the number of processes in the system
m is the number of resource types
• Available - Vector of length m. If available [j] = k, there are k instances of
resource type Rj available
• Max - n x m matrix. If Max [i,j] = k, then process Pi may request at most k
instances of resource type Rj
• Allocation - n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k
instances of Rj
• Need - n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to
complete its task
Need [i,j] = Max[i,j] – Allocation [i,j]
• These data structures vary over time in both size and value
Banker’s Algorithm
12
• The vector Allocationi specifies the resources currently allocated to process Pi
• The vector Needi specifies the additional resources that process Pi may still request
to complete its task
• In Banker’s algorithm, we have two types –
• Safety algorithm
• Resource Allocation algorithm
• Safety Algorithm
• The algorithm for finding out whether or not a system is in a safe state. This
algorithm can be described as follows -
• Let Work and Finish be vectors of length m and n, respectively. Initialize -
• Work = Available
• Finish [i] = false for i = 0, 1, …, n- 1
Banker’s Algorithm
13
• Safety Algorithm
1. Let Work and Finish be vectors of length m and n, respectively. Initialize:
• Work = Available
• Finish [i] = false for i = 0, 1, …, n- 1
2. Find an index i such that both
• Finish[i] == false
• Needi ≤ 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] == true for all i, then the system is in a safe state
• This algorithm may require an order of m × n2 operations to determine whether a
state is safe
Banker’s Algorithm
14
• Resource Request Algorithm
• Algorithm for determining whether requests can be safely granted
• Let Requesti be the request vector for process Pi
• If Requesti [j] == k, then process Pi wants k instances of resource type Rj
• When a request for resources is made by process Pi , the following actions are
taken
1. If Requesti (less than or equal to) Needi go to step 2. Otherwise, raise error
condition, since process has exceeded its maximum claim
2. If Requesti (less than or equal to) Available, go to step 3. Otherwise Pi
must wait, since resources are not available
3. Pretend to allocate requested resources to Pi by modifying the state as
follows: Available = Available – Requesti;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
Banker’s Algorithm
15
Pro: Consider a system with five processes
P0 through P4 and three resource types A,
B, and C. Resource type A has ten
instances, resource type B has five
instances, and resource type C has seven
instances
Sol:
Given: A B C – 3 resource types
A=10 instances; B=5 instances;
C = 7 instances
- Total number of resources = 10+5+7 = 22
resources
- Number of resources available of
Resource type A = 10-7 = 3
B= 5-2 =3
C= 7-5 =2
Banker’s Algorithm
16
Proc
ess
Allocati
on
Max Availab
le
Need
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
7 2 5
Need [i,j] = Max[i,j] – Allocation [i,j]
• Safety Algorithm
Banker’s Algorithm
17
• Work= available then work= 3 3 2
• Finish[i]=false i=0,1,2,3,4 ; false indicate not executed
1. P0
Work= available ; work=3 3 2
finish[i]=false;
need<= work ; 7 4 3<= 3 3 2 --> false
So, P0 has to wait
2. P1
need <= work 1 2 2 <= 3 3 2 true
work= work+ allocation
3 3 2 +2 0 0 = 5 3 2 available; P1 starts its execution
Work = 5 3 2
• Safety Algorithm
Banker’s Algorithm
18
3. P2
need <= work 6 0 0 <= 5 3 2 false
p2 has to wait
4. P3
need <= work 0 1 1<= 5 3 2 true
work= work+ allocation
5 3 2 +2 1 1 = 7 4 3 available
5. P4
need <= work 4 3 1<= 7 4 3 true
work= work+ allocation
7 4 3 + 0 0 2 = 7 4 5 available
• Safety Algorithm
Banker’s Algorithm
19
6. P0
need <= work 7 4 3<= 7 4 5 true
work= work+ allocation
=7 4 5 + 0 1 0 = 7 5 5 available
7. P2
need <= work 6 0 0<= 7 5 5 true
work= work+ allocation
=7 5 5 +3 0 2= 10 5 7 available
• Finish 0 1 2 3 4
false false false false false
T4 T1 T5 T2 T3
Let P1 request for (1 0 2)
1. Check Request <= Need
(1 0 2 <= 1 2 2) - true
2. Check that Request <= Available
(1,0,2) <= (3,3,2) - true
3. allocation= allocation + request
2 0 0 + 1 0 2 =3 0 2
available = available –request
3 3 2- 1 0 2 = 2 3 0
need= need – request
1 2 2 -1 0 2= 0 2 0
Banker’s Algorithm
20
Proc
ess
Allocati
on
Max Availab
le
Need
A B C A B C A B C A B C
P0 0 1 0 7 5 3 2 3 0 7 4 3
P1 3 0 2 3 2 2 0 2 0
P2 3 0 2 9 0 2 6 0 0
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
8 2 7
A B C – 3 resource types
A=10 instances; B=5 instances;
C = 7 instances
• Safety Algorithm
Banker’s Algorithm
21
1. P0
Need<= work 7 4 3 <= 2 3 0 false
P0 has to wait
2. P1
Need<= work 0 2 0 <= 2 3 0 true
work= work + allocation = 2 3 0 + 3 0 2 = 5 3 2
3. P2
Need<= work 6 0 0 <= 5 3 2 false
P2 has to wait
4. P3
Need<= work 0 1 1 <= 5 3 2 true
work= work + allocation = 5 3 2 + 2 1 1 = 7 4 3
5. P4
Need<= work 4 3 1 <= 7 4 3 true
work= work + allocation = 7 4 3 + 0 0 2 = 7 4 5
• Safety Algorithm
Banker’s Algorithm
22
6. P0
Need<= work 7 4 3 <= 7 4 5 true
work= work + allocation = 7 4 5 + 0 1 0 = 7 5 5
7. P2
Need<= work 6 0 0 <= 7 5 5 true
work= work + allocation = 7 5 5 + 3 0 2 = 10 5 7
• So, safe sequence for the execution is <P1,P3,P4,P0,P2>
• Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies
safety requirement
23
References
1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition,
John Wiley and Sons, 2012.
24
Thank you

Weitere ähnliche Inhalte

Ähnlich wie Deadlocks Part- II.pdf

Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptxshreesha16
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptxshrijanasharma3
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxBhaskar271887
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.pptKAnurag2
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OSC.U
 
26 to 27deadlockavoidance
26 to 27deadlockavoidance26 to 27deadlockavoidance
26 to 27deadlockavoidancemyrajendra
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserMatthew Chang
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptxKokilaK25
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxssusere16bd9
 

Ähnlich wie Deadlocks Part- II.pdf (20)

Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Ch07 deadlocks
Ch07 deadlocksCh07 deadlocks
Ch07 deadlocks
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Os5
Os5Os5
Os5
 
Deadlocks Part- III.pdf
Deadlocks Part- III.pdfDeadlocks Part- III.pdf
Deadlocks Part- III.pdf
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
26 to 27deadlockavoidance
26 to 27deadlockavoidance26 to 27deadlockavoidance
26 to 27deadlockavoidance
 
The implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parserThe implementation of Banker's algorithm, data structure and its parser
The implementation of Banker's algorithm, data structure and its parser
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
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
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 

Kürzlich hochgeladen (20)

Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
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
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
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
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 

Deadlocks Part- II.pdf

  • 2. • System Model • Deadlock Characterization • Methods for Handling Deadlocks • Deadlock Prevention • Deadlock Avoidance • Deadlock Detection • Recovery from Deadlock 2
  • 3. Dead Avoidance • Possible side effects of preventing deadlocks with Deadlock prevention are - • Low device utilization and reduced system throughput • Deadlock avoidance requires additional information about how resources have to be requested • Example - • In a system with one tape drive and one printer • The system might need to know that process P will request first the tape drive and then the printer before releasing both resources • Process Q will request first the printer and then the tape drive • With this knowledge of the complete sequence of requests and releases for each process, the system can decide for each request whether or not the process should wait in order to avoid a possible future deadlock 3
  • 4. Dead Avoidance • Each request requires that in making this decision, the system follows the followig approach - • the resources currently available, • the resources currently allocated to each process • the future requests and releases of each process • Algorithms that use this approach differ in the amount and type of information required • The simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need • A deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that a circular-wait condition can never exist • Resource Allocation state is defined by the number of available and allocated resources and the maximum demands of the processes 4
  • 5. • A state is safe if the system can allocate resources to each process in some order and still avoid a deadlock • A system is in a safe state only if there exists a safe sequence • Safe sequence: A sequence of processes <P1, P2, …, Pn> is a safe sequence for the current allocation state if, for each Pi , the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j < i • In this situation, • If the resources that Pi needs are not immediately available, then Pi can wait until all Pj have finished • When all Pj are finished, Pi can obtain needed resources, execute, return allocated resources, and terminate • When Pi terminates, Pi +1 can obtain its needed resources, and so on • If no such sequence exists, then the system state is said to be unsafe Safe State 5
  • 6. • If a system is in unsafe state possibility of deadlock • An unsafe state may lead to a deadlock • In an unsafe state, the operating system cannot prevent processes from requesting resources in such a way that a deadlock occurs. The behavior of the processes controls unsafe states • Avoidance ensure that a system will never enter an unsafe state • If a system is in safe state no deadlocks • As long as the state is safe, the operating system can avoid unsafe (and deadlocked) states Safe State 6
  • 8. • Resource - Allocation - Graph Algorithm • Banker’s Algorithm • Idea behind deadlock avoidance algorithm - • To ensure that the system will always remain in a safe state • Whenever a process requests a resource that is currently available, the system must decide whether the resource can be allocated immediately or whether the process must wait • The request is granted only if the allocation leaves the system in a safe state • In this scheme, if a process requests a resource that is currently available, it may still have to wait • Thus, resource utilization may be lower than it would be • Single instance of a resource type • Use a resource-allocation graph • Multiple instances of a resource type • Use the banker’s algorithm Two deadlock-avoidance algorithms 8
  • 9. • Claim edge - Pi -->Rj indicates that process Pi may request resource Rj at some time in the future and it is represented by a dashed line • Claim edge converts to request edge when a process requests a resource • Request edge converted to an assignment edge when the resource is allocated to the process • When a resource is released by a process, assignment edge reconverts to a claim edge • Resources must be claimed a priori in the system. That is, before process Pi starts executing, all its claim edges must already appear in the resource-allocation graph • Suppose that process Pi requests a resource Rj • The request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph • Here, we need a cycle detection algorithm that requires an order of n*n operations, where n is the number of processes in the system Resource-Allocation-Graph Algorithm 9
  • 10. • If no cycle exists, then the allocation of the resource will leave the system in a safe state. If a cycle is found, then the allocation will put the system in an unsafe state. In that case, process Pi will have to wait for its requests to be satisfied • Consider the resource-allocation graph, suppose that P2 requests R2 • Although R2 is currently free, cannot allocate it to P2, since this action will create a cycle in the graph • A cycle, as mentioned, indicates that the system is in an unsafe state • If P1 requests R2, and P2 requests R1, then a deadlock will occur Resource-Allocation-Graph Algorithm 10
  • 11. • When each resource has multiple instance then banker algorithm is used • When a new process enters the system, it must declare the maximum number of instances of each resource type that it may need • Number may not exceed the total number of resources in the system • When a user requests a set of resources, the system must determine whether the allocation of these resources will leave the system in a safe state • If it will, the resources are allocated; otherwise, the process must wait until some other process releases enough resources • When a process gets all its resources it must return them in a finite amount of time • Data structures must be maintained to implement the banker’s algorithm, to encode the state of the resource-allocation system Banker’s Algorithm 11
  • 12. • The following data structures are used in this algorithm n is the number of processes in the system m is the number of resource types • Available - Vector of length m. If available [j] = k, there are k instances of resource type Rj available • Max - n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj • Allocation - n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj • Need - n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task Need [i,j] = Max[i,j] – Allocation [i,j] • These data structures vary over time in both size and value Banker’s Algorithm 12
  • 13. • The vector Allocationi specifies the resources currently allocated to process Pi • The vector Needi specifies the additional resources that process Pi may still request to complete its task • In Banker’s algorithm, we have two types – • Safety algorithm • Resource Allocation algorithm • Safety Algorithm • The algorithm for finding out whether or not a system is in a safe state. This algorithm can be described as follows - • Let Work and Finish be vectors of length m and n, respectively. Initialize - • Work = Available • Finish [i] = false for i = 0, 1, …, n- 1 Banker’s Algorithm 13
  • 14. • Safety Algorithm 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: • Work = Available • Finish [i] = false for i = 0, 1, …, n- 1 2. Find an index i such that both • Finish[i] == false • Needi ≤ 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] == true for all i, then the system is in a safe state • This algorithm may require an order of m × n2 operations to determine whether a state is safe Banker’s Algorithm 14
  • 15. • Resource Request Algorithm • Algorithm for determining whether requests can be safely granted • Let Requesti be the request vector for process Pi • If Requesti [j] == k, then process Pi wants k instances of resource type Rj • When a request for resources is made by process Pi , the following actions are taken 1. If Requesti (less than or equal to) Needi go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim 2. If Requesti (less than or equal to) Available, go to step 3. Otherwise Pi must wait, since resources are not available 3. Pretend to allocate requested resources to Pi by modifying the state as follows: Available = Available – Requesti; Allocationi = Allocationi + Requesti; Needi = Needi – Requesti; Banker’s Algorithm 15
  • 16. Pro: Consider a system with five processes P0 through P4 and three resource types A, B, and C. Resource type A has ten instances, resource type B has five instances, and resource type C has seven instances Sol: Given: A B C – 3 resource types A=10 instances; B=5 instances; C = 7 instances - Total number of resources = 10+5+7 = 22 resources - Number of resources available of Resource type A = 10-7 = 3 B= 5-2 =3 C= 7-5 =2 Banker’s Algorithm 16 Proc ess Allocati on Max Availab le Need A B C A B C A B C A B C P0 0 1 0 7 5 3 3 3 2 7 4 3 P1 2 0 0 3 2 2 1 2 2 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1 7 2 5 Need [i,j] = Max[i,j] – Allocation [i,j]
  • 17. • Safety Algorithm Banker’s Algorithm 17 • Work= available then work= 3 3 2 • Finish[i]=false i=0,1,2,3,4 ; false indicate not executed 1. P0 Work= available ; work=3 3 2 finish[i]=false; need<= work ; 7 4 3<= 3 3 2 --> false So, P0 has to wait 2. P1 need <= work 1 2 2 <= 3 3 2 true work= work+ allocation 3 3 2 +2 0 0 = 5 3 2 available; P1 starts its execution Work = 5 3 2
  • 18. • Safety Algorithm Banker’s Algorithm 18 3. P2 need <= work 6 0 0 <= 5 3 2 false p2 has to wait 4. P3 need <= work 0 1 1<= 5 3 2 true work= work+ allocation 5 3 2 +2 1 1 = 7 4 3 available 5. P4 need <= work 4 3 1<= 7 4 3 true work= work+ allocation 7 4 3 + 0 0 2 = 7 4 5 available
  • 19. • Safety Algorithm Banker’s Algorithm 19 6. P0 need <= work 7 4 3<= 7 4 5 true work= work+ allocation =7 4 5 + 0 1 0 = 7 5 5 available 7. P2 need <= work 6 0 0<= 7 5 5 true work= work+ allocation =7 5 5 +3 0 2= 10 5 7 available • Finish 0 1 2 3 4 false false false false false T4 T1 T5 T2 T3
  • 20. Let P1 request for (1 0 2) 1. Check Request <= Need (1 0 2 <= 1 2 2) - true 2. Check that Request <= Available (1,0,2) <= (3,3,2) - true 3. allocation= allocation + request 2 0 0 + 1 0 2 =3 0 2 available = available –request 3 3 2- 1 0 2 = 2 3 0 need= need – request 1 2 2 -1 0 2= 0 2 0 Banker’s Algorithm 20 Proc ess Allocati on Max Availab le Need A B C A B C A B C A B C P0 0 1 0 7 5 3 2 3 0 7 4 3 P1 3 0 2 3 2 2 0 2 0 P2 3 0 2 9 0 2 6 0 0 P3 2 1 1 2 2 2 0 1 1 P4 0 0 2 4 3 3 4 3 1 8 2 7 A B C – 3 resource types A=10 instances; B=5 instances; C = 7 instances
  • 21. • Safety Algorithm Banker’s Algorithm 21 1. P0 Need<= work 7 4 3 <= 2 3 0 false P0 has to wait 2. P1 Need<= work 0 2 0 <= 2 3 0 true work= work + allocation = 2 3 0 + 3 0 2 = 5 3 2 3. P2 Need<= work 6 0 0 <= 5 3 2 false P2 has to wait 4. P3 Need<= work 0 1 1 <= 5 3 2 true work= work + allocation = 5 3 2 + 2 1 1 = 7 4 3 5. P4 Need<= work 4 3 1 <= 7 4 3 true work= work + allocation = 7 4 3 + 0 0 2 = 7 4 5
  • 22. • Safety Algorithm Banker’s Algorithm 22 6. P0 Need<= work 7 4 3 <= 7 4 5 true work= work + allocation = 7 4 5 + 0 1 0 = 7 5 5 7. P2 Need<= work 6 0 0 <= 7 5 5 true work= work + allocation = 7 5 5 + 3 0 2 = 10 5 7 • So, safe sequence for the execution is <P1,P3,P4,P0,P2> • Executing safety algorithm shows that sequence < P1, P3, P4, P0, P2> satisfies safety requirement
  • 23. 23 References 1. Silberscatnz and Galvin, “Operating System Concepts,” Ninth Edition, John Wiley and Sons, 2012.