SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Understand Process Management

• Deadlock Avoidance




                                       1
HOME     PREVIOUS TOPIC
NEXT
PREVIOUS QUESTION PAPERS
FOR OS
CPP TUTORIALS




                           2
Recap

In the last class, you have learnt:
•       Various techniques for Deadlock Prevention namely
    –     Denying mutual exclusion condition
    –     Ensuring that hold and wait condition never occurs
    –     Ensuring that no preemption of resources does not hold
    –     Ensuring that the circular wait condition never holds


                                                                  3
Objectives
On completion of this class, you would be able to

know:
• Deadlock Avoidance

• Safe state

• Resource allocation Graph Algorithm

• Banker’s Algorithm

                                                    4
Deadlock Avoidance

• To avoid a deadlock we require additional information
  about how resources are to be requested
• Example :
   – In a system with one tape drive and one printer, it needs to know
     that process P & Q will request which one first




                                                                5
Deadlock Avoidance

• With this knowledge of complete sequence of
  requests and releases of resources for each process
   – It is possible to construct algorithms that ensures that
     the system will never enter a deadlock state
• A deadlock avoidance algorithm dynamically
  examines that a circular wait condition can never
  exist
                                                                6
Safe State

• A state is safe if the system can allocate resources to each
  process in some order still avoid a deadlock
• A system is in a safe state only if there exists a 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 the currently available resources
   – plus the resources held by all the Pj with j < i                 7
Safe State

                          unsafe
        deadlock

                             safe




Fig – 1, Safe, unsafe and deadlock state spaces
                                                  8
Safe State and Unsafe State

• A safe state is not a deadlock state

• A deadlock state is an unsafe state

• All unsafe states may not lead to a deadlock state

• A system may go from a safe state to an unsafe state


                                                       9
Resource Allocation Graph

• Here we introduce a new type of edge called claim edge

• Claim edge represented by a dashed line

• A claim edge Pi    Rj indicates that process Pi may

  request resource Rj in future

• When process Pi requests resource Rj, the claim edge Pi

     Rj is converted to a request edge

                                                        10
Resource Allocation Graph (contd.)

                       R1




       P1                                  P2




                        R2

Fig – 2, Resource Allocation Graph for Deadlock Avoidance
                                                       11
Resource Allocation Graph


Draw backs of resource allocation graph algorithm
• Not applicable to a resource- allocation system with
  multiple instances of each resource type




                                                    12
Banker’s Algorithm

• New process must declare maximum no of instances of
  each resource type that it may need
• This number may not exceed the total no of resources in
  the system
• When user requests a set of resources, system must
  determine whether allocation of these resources will
  retain safe state
• Resources are allocated only if it leads to a safe state
  otherwise not allocated
                                                        13
Banker’s algorithm


• Applicable to systems with multiple instances of
  each resource type
• Less efficiency than the resources- allocation
  graph algorithm




                                                     14
Banker’s Algorithm

                           R1




         P1                                     P2




                           R2

Fig – 3, An unsafe state in a resource allocation graph
                                                          15
Data Structures needed to implement the
             Banker’s Algorithm

• Let n be the number of processes in the system

• Let m be the number of resource types

• The following data structures are needed
      1. Available

      2. Max

      3. Allocation

      4. Need
                                                   16
Data Structures needed to implement the
             Banker’s Algorithm

Available
• A vector of length m indicates the number of
  available resources of each type
• If available[j]=k, there are k instances of resource
  type Rj available


                                                         17
Data Structures needed to implement the
             Banker’s Algorithm

Max
• An n x m matrix defines the maximum demand of
  each process

• If Max[i,j]=k, then process Pi may request at most

  k instances of resource type Rj

                                                   18
Data Structures needed to implement the
             Banker’s Algorithm

Allocation

• An n x m matrix defines the number of resources of
  each type currently allocated to each process

• If Allocation[i,j]=k, then process Pi is currently

  allocated k instances of resource type Rj


                                                       19
Data Structures Needed to implement the
               Banker’s Algorithm

Need
• An n x m matrix indicates the remaining resource need
  of each process

• If Need[i,j]=k, then process Pi may need k more

  instances of resource type Rj to complete its task

• Note that Need[i,j] = Max[i,j] - Allocation[i,j]

                                                       20
Summary


•   Deadlock avoidance requires prior information on
    how each process will be utilizing the resources
•   Banker’s algorithm needs to know the maximum
    number of each resource type that may be requested
    by each process



                                                       21
Frequently Asked Questions

1. Explain Deadlock Avoidance

2. Explain Banker’s Algorithm




                                     22
Quiz

1. Banker’s algorithm is more efficient than resource
   allocation graph scheme
   a) True
   b) False
2. An unsafe state always leads to a deadlock
   a) True
   b) False
3. A safe state is not a deadlock state
   a) True
   b) False
                                                  23
Other subject materials
•   Web designing
•   Micro processors
•   C++ tutorials
•   java

home
Quiz


4. A unsafe state is not a deadlock state

a) True

b) False




                                            25

Weitere ähnliche Inhalte

Andere mochten auch

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 
Process management
Process managementProcess management
Process management
Mohd Arif
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
Sonali Chauhan
 

Andere mochten auch (17)

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
 
Deadlock Detection
Deadlock DetectionDeadlock Detection
Deadlock Detection
 
Operating system Dead lock
Operating system Dead lockOperating system Dead lock
Operating system Dead lock
 
Chapter 4 - Threads
Chapter 4 - ThreadsChapter 4 - Threads
Chapter 4 - Threads
 
Threads
ThreadsThreads
Threads
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 
OS Process and Thread Concepts
OS Process and Thread ConceptsOS Process and Thread Concepts
OS Process and Thread Concepts
 
Process of operating system
Process of operating systemProcess of operating system
Process of operating system
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Operating Systems - Processor Management
Operating Systems - Processor ManagementOperating Systems - Processor Management
Operating Systems - Processor Management
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Operating system - Process and its concepts
Operating system - Process and its conceptsOperating system - Process and its concepts
Operating system - Process and its concepts
 
Process management in os
Process management in osProcess management in os
Process management in os
 
Process management
Process managementProcess management
Process management
 
CPU Scheduling Algorithms
CPU Scheduling AlgorithmsCPU Scheduling Algorithms
CPU Scheduling Algorithms
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 

Ähnlich wie 26 to 27deadlockavoidance

DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
hetrathod001
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
shreesha16
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
Bhaskar271887
 
28 to 29 detection
28 to 29 detection 28 to 29 detection
28 to 29 detection
myrajendra
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
Unknown664473
 
Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptx
ssuserca5764
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
KokilaK25
 

Ähnlich wie 26 to 27deadlockavoidance (20)

DeadlockMar21.ppt
DeadlockMar21.pptDeadlockMar21.ppt
DeadlockMar21.ppt
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Deadlocks Part- II.pdf
Deadlocks Part- II.pdfDeadlocks Part- II.pdf
Deadlocks Part- II.pdf
 
deadlock part5 unit 2.ppt
deadlock part5 unit 2.pptdeadlock part5 unit 2.ppt
deadlock part5 unit 2.ppt
 
Os5
Os5Os5
Os5
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Ch7 deadlocks
Ch7   deadlocksCh7   deadlocks
Ch7 deadlocks
 
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
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
28 to 29 detection
28 to 29 detection 28 to 29 detection
28 to 29 detection
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptx
 
Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptx
 
6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx6. Deadlock_1640227623705.pptx
6. Deadlock_1640227623705.pptx
 
OS Module-3 (2).pptx
OS Module-3 (2).pptxOS Module-3 (2).pptx
OS Module-3 (2).pptx
 
Mca ii os u-3 dead lock & io systems
Mca  ii  os u-3 dead lock & io systemsMca  ii  os u-3 dead lock & io systems
Mca ii os u-3 dead lock & io systems
 
Deadlocks Part- I.pdf
Deadlocks Part- I.pdfDeadlocks Part- I.pdf
Deadlocks Part- I.pdf
 
Deadlock
DeadlockDeadlock
Deadlock
 
23 deadlock
23 deadlock23 deadlock
23 deadlock
 

Mehr von myrajendra (20)

Fundamentals
FundamentalsFundamentals
Fundamentals
 
Data type
Data typeData type
Data type
 
Hibernate example1
Hibernate example1Hibernate example1
Hibernate example1
 
Jdbc workflow
Jdbc workflowJdbc workflow
Jdbc workflow
 
2 jdbc drivers
2 jdbc drivers2 jdbc drivers
2 jdbc drivers
 
3 jdbc api
3 jdbc api3 jdbc api
3 jdbc api
 
4 jdbc step1
4 jdbc step14 jdbc step1
4 jdbc step1
 
Dao example
Dao exampleDao example
Dao example
 
Sessionex1
Sessionex1Sessionex1
Sessionex1
 
Internal
InternalInternal
Internal
 
3. elements
3. elements3. elements
3. elements
 
2. attributes
2. attributes2. attributes
2. attributes
 
1 introduction to html
1 introduction to html1 introduction to html
1 introduction to html
 
Headings
HeadingsHeadings
Headings
 
Forms
FormsForms
Forms
 
Css
CssCss
Css
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Views
ViewsViews
Views
 
Starting jdbc
Starting jdbcStarting jdbc
Starting jdbc
 

26 to 27deadlockavoidance

  • 1. Understand Process Management • Deadlock Avoidance 1
  • 2. HOME PREVIOUS TOPIC NEXT PREVIOUS QUESTION PAPERS FOR OS CPP TUTORIALS 2
  • 3. Recap In the last class, you have learnt: • Various techniques for Deadlock Prevention namely – Denying mutual exclusion condition – Ensuring that hold and wait condition never occurs – Ensuring that no preemption of resources does not hold – Ensuring that the circular wait condition never holds 3
  • 4. Objectives On completion of this class, you would be able to know: • Deadlock Avoidance • Safe state • Resource allocation Graph Algorithm • Banker’s Algorithm 4
  • 5. Deadlock Avoidance • To avoid a deadlock we require additional information about how resources are to be requested • Example : – In a system with one tape drive and one printer, it needs to know that process P & Q will request which one first 5
  • 6. Deadlock Avoidance • With this knowledge of complete sequence of requests and releases of resources for each process – It is possible to construct algorithms that ensures that the system will never enter a deadlock state • A deadlock avoidance algorithm dynamically examines that a circular wait condition can never exist 6
  • 7. Safe State • A state is safe if the system can allocate resources to each process in some order still avoid a deadlock • A system is in a safe state only if there exists a 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 the currently available resources – plus the resources held by all the Pj with j < i 7
  • 8. Safe State unsafe deadlock safe Fig – 1, Safe, unsafe and deadlock state spaces 8
  • 9. Safe State and Unsafe State • A safe state is not a deadlock state • A deadlock state is an unsafe state • All unsafe states may not lead to a deadlock state • A system may go from a safe state to an unsafe state 9
  • 10. Resource Allocation Graph • Here we introduce a new type of edge called claim edge • Claim edge represented by a dashed line • A claim edge Pi Rj indicates that process Pi may request resource Rj in future • When process Pi requests resource Rj, the claim edge Pi Rj is converted to a request edge 10
  • 11. Resource Allocation Graph (contd.) R1 P1 P2 R2 Fig – 2, Resource Allocation Graph for Deadlock Avoidance 11
  • 12. Resource Allocation Graph Draw backs of resource allocation graph algorithm • Not applicable to a resource- allocation system with multiple instances of each resource type 12
  • 13. Banker’s Algorithm • New process must declare maximum no of instances of each resource type that it may need • This number may not exceed the total no of resources in the system • When user requests a set of resources, system must determine whether allocation of these resources will retain safe state • Resources are allocated only if it leads to a safe state otherwise not allocated 13
  • 14. Banker’s algorithm • Applicable to systems with multiple instances of each resource type • Less efficiency than the resources- allocation graph algorithm 14
  • 15. Banker’s Algorithm R1 P1 P2 R2 Fig – 3, An unsafe state in a resource allocation graph 15
  • 16. Data Structures needed to implement the Banker’s Algorithm • Let n be the number of processes in the system • Let m be the number of resource types • The following data structures are needed 1. Available 2. Max 3. Allocation 4. Need 16
  • 17. Data Structures needed to implement the Banker’s Algorithm Available • A vector of length m indicates the number of available resources of each type • If available[j]=k, there are k instances of resource type Rj available 17
  • 18. Data Structures needed to implement the Banker’s Algorithm Max • An n x m matrix defines the maximum demand of each process • If Max[i,j]=k, then process Pi may request at most k instances of resource type Rj 18
  • 19. Data Structures needed to implement the Banker’s Algorithm Allocation • An n x m matrix defines the number of resources of each type currently allocated to each process • If Allocation[i,j]=k, then process Pi is currently allocated k instances of resource type Rj 19
  • 20. Data Structures Needed to implement the Banker’s Algorithm Need • An n x m matrix indicates the remaining resource need of each process • If Need[i,j]=k, then process Pi may need k more instances of resource type Rj to complete its task • Note that Need[i,j] = Max[i,j] - Allocation[i,j] 20
  • 21. Summary • Deadlock avoidance requires prior information on how each process will be utilizing the resources • Banker’s algorithm needs to know the maximum number of each resource type that may be requested by each process 21
  • 22. Frequently Asked Questions 1. Explain Deadlock Avoidance 2. Explain Banker’s Algorithm 22
  • 23. Quiz 1. Banker’s algorithm is more efficient than resource allocation graph scheme a) True b) False 2. An unsafe state always leads to a deadlock a) True b) False 3. A safe state is not a deadlock state a) True b) False 23
  • 24. Other subject materials • Web designing • Micro processors • C++ tutorials • java home
  • 25. Quiz 4. A unsafe state is not a deadlock state a) True b) False 25