SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
Deadlock

  Organized By: Vinay Arora
                 Assistant Professor
                 CSED, TU




                                V.A.
                              CSED,TU
Disclaimer

           This is NOT A COPYRIGHT          MATERIAL


   Content has been taken mainly from the following books:

        Operating Systems Concepts By Silberschatz & Galvin,
Operating Systems: Internals and Design Principles By William Stallings
                        www.os-book.com
         www.cs.jhu.edu/~yairamir/cs418/os2/sld001.htm
     www.personal.kent.edu/~rmuhamma/OpSystems/os.html
 http://msdn.microsoft.com/en-us/library/ms685096(VS.85).aspx
http://www.computer.howsttuffworks.com/operating-system6.htm
         http://williamstallings.com/OS/Animations.html
                               Etc…

                                 VA.
                               CSED,TU
Deadlock – Real Life Scenario




                   VA.
                 CSED,TU
System Model
   Resource types R1, R2, . . ., Rm

        CPU cycles, memory space, I/O devices

   Each resource type Ri has Wi instances.

   Each process utilizes a resource as follows:

       request

       use

       release
                                        VA.
                                      CSED,TU
Deadlock Characterization
   Mutual Exclusion: only one process at a time can use a resource.

   Hold and Wait: a process holding at least one resource is waiting to
   acquire additional resources held by other processes.

   No Preemption: a resource can be released only voluntarily by the
   process holding it, after that process has completed its task.

   Circular Wait: there exists a set {P0, P1, …, P0} of waiting processes
   such that P0 is waiting for a resource that is held by P1, P1 is waiting for
   a resource that is held by

        P2, …, Pn–1 is waiting for a resource that is held by

        Pn, and P0 is waiting for a resource that is held by P0.

                                      VA.
                                    CSED,TU
RAG
 A set of vertices V and a set of edges E.

 V is partitioned into two types:
     P = {P1, P2, …, Pn}, the set consisting of all the processes in the
     system.

     R = {R1, R2, …, Rm}, the set consisting of all resource types in the
     system.
 request edge – directed edge P1 → Rj

 assignment edge – directed edge Rj → Pi



                                   VA.
                                 CSED,TU
Process



Resource Type with 4 instances


Pi requests instance of Rj             Pi




Pi is holding an instance of Rj        Pi

                               VA.
                             CSED,TU
Example - RAG




                  VA.
                CSED,TU
RAG with Deadlock




                 VA.
               CSED,TU
RAG with no Deadlock




                  VA.
                CSED,TU
Basic Facts

   If graph contains no cycles ⇒ no deadlock.

   If graph contains a cycle ⇒

      if only one instance per resource type, then deadlock.

      if several instances per resource type, possibility of deadlock.




                                    VA.
                                  CSED,TU
Deadlock Prevention
   Mutual Exclusion – not required for sharable resources; must hold for
   non sharable resources.

   Hold and Wait – must guarantee that whenever a process requests a
   resource, it does not hold any other resources.

      Require process to request and be allocated all its resources before it
      begins execution, or allow process to request resources only when
      the process has none.

      Low resource utilization; starvation possible.



                                    VA.
                                  CSED,TU
No Preemption –

    If a process that is holding some resources requests another resource
    that cannot be immediately allocated to it, then all resources
    currently being held are released.
    Preempted resources are added to the list of resources for which the
    process is waiting.
    Process will be restarted only when it can regain its old resources, as
    well as the new ones that it is requesting.

Circular Wait – impose a total ordering of all resource types, and require
that each process requests resources in an increasing order of
enumeration.


                                  VA.
                                CSED,TU
Safe, Unsafe & Deadlock State




                   VA.
                 CSED,TU
Banker’s Algorithm – Safety Algo.
 1. Let Work and Finish be vectors of length m and n, respectively.
    Initialize Work = Available and Finish[i]=False for i=0,1,2……,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.
                                          VA.
                                        CSED,TU
Banker’s Algo. – Resource Request Algo.

  1.   If Requesti < Needi, go to step 2. Otherwise, raise an error condition,
       since the process has exceeded its maximum claim.

  2.   If Requesti < Available, go to step 3. Otherwise, Pi must wait, since
       the resources are not available.

  3.   Have the system pretend to have allocated the requested resources to
       process Pi by modifying the state as follows:
                   Available = Available – Requesti
                   Allocationi =Allocationi + Requesti
                   Needi = Needi - Requesti



                                      VA.
                                    CSED,TU
Problem Statement
          Allocation    Max        Available
           A B C       A B C       A B C
    P0     0 1 0       7 5 3        3 3 2
    P1     2 0 0       3 2 2
    P2     3 0 2       9 0 2
    P3     2 1 1       2 2 2
    P4     0 0 2       4 3 3

 Request1 = (1,0,2)

 After Calculating the Matrix Execute for below mentioned Requests
 Request0 = (0,2,0)
 Request4 = (3,3,0)

                                       VA.
                                     CSED,TU
Deadlock Detection

   Allow system to enter deadlock state



   Detection algorithm



   Recovery scheme




                                   VA.
                                 CSED,TU
Single Instance of each Resource Type

  Maintain wait-for graph



  Nodes are processes.

      Pi → Pj if Pi is waiting for Pj.



  Periodically invoke an algorithm that searches for a cycle in the graph.




                                     VA.
                                   CSED,TU
RAG & Wait For Graph




                  VA.
                CSED,TU
Several Instances of resource Type
   Available: A vector of length m indicates the number of available
   resources of each type.



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



   Request: An n x m matrix indicates the current request of each process.
   If Request [ij] = k, then process Pi is requesting k more instances of
   resource type. Rj.



                                   VA.
                                 CSED,TU
Deadlock Detection
 1. Let Work and Finish be vectors of length m and n, respectively.
    Initialize Work = Available. For i=0,1,2……,n-1, if Allocationi Not equal
    to ZERO, then Finish[i] = False; Otherwise,Finish[i] = True

 2. Find an index i such that both
        Finish[i] = = False
        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, then the system is in Deadlock State.

                                           VA.
                                         CSED,TU
Problem Statement
        Allocation    Request   Available
        A B C         A B C     A B C
   P0    0 1 0        0 0 0     0 0 0
   P1    2 0 0        2 0 2
   P2    3 0 3        0 0 0
   P3    2 1 1        1 0 0
   P4    0 0 2        0 0 2


                     Request
                     A B C
                     0 0 0
                     2 0 2
                     0 0 1
                     1 0 0
                     0 0 2

                                        VA.
                                      CSED,TU
Recovery from Deadlock – Process
                    Termination
Abort all deadlocked processes.

Abort one process at a time until the deadlock cycle is eliminated.

In which order should we choose to abort?

   Priority of the process.
   How long process has computed, and how much longer to
   completion.
   Resources the process has used.
   Resources process needs to complete.
   How many processes will need to be terminated.

                                 VA.
                               CSED,TU
Recovery from Deadlock – Resource
            Preemption

Selecting a victim – minimize cost.



Rollback – return to some safe state, restart process for that state.



Starvation – same process may always be picked as victim, include
number of rollback in cost factor.




                                   VA.
                                 CSED,TU
Thnx…



    VA.
  CSED,TU

Mais conteúdo relacionado

Mais procurados

Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
Sonali Chauhan
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 

Mais procurados (20)

Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Operating System: Deadlock
Operating System: DeadlockOperating System: Deadlock
Operating System: Deadlock
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock in Operating System
Deadlock in Operating SystemDeadlock in Operating System
Deadlock in Operating System
 
Deadlock
DeadlockDeadlock
Deadlock
 
7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
deadlock handling
deadlock handlingdeadlock handling
deadlock handling
 
Bankers algorithm
Bankers algorithmBankers algorithm
Bankers algorithm
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Deadlocks
DeadlocksDeadlocks
Deadlocks
 
Deadlock
DeadlockDeadlock
Deadlock
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURYdeadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
deadlock detection using Goldman's algorithm by ANIKET CHOUDHURY
 
Deadlock Presentation
Deadlock PresentationDeadlock Presentation
Deadlock Presentation
 

Semelhante a OS - Deadlock

Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
marangburu42
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
Rushdi Shams
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
C.U
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
tech2click
 

Semelhante a OS - Deadlock (20)

Deadlock Detection Algorithm
Deadlock Detection AlgorithmDeadlock Detection Algorithm
Deadlock Detection Algorithm
 
CSS430_Deadlock.pptx
CSS430_Deadlock.pptxCSS430_Deadlock.pptx
CSS430_Deadlock.pptx
 
Ice
IceIce
Ice
 
Bankers
BankersBankers
Bankers
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
Operating System
Operating SystemOperating System
Operating System
 
Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232Deadlocks 160928121516-160928183232
Deadlocks 160928121516-160928183232
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Deadlock
DeadlockDeadlock
Deadlock
 
Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Deadlock and Banking Algorithm
Deadlock and Banking AlgorithmDeadlock and Banking Algorithm
Deadlock and Banking Algorithm
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 

Mais de vinay arora (20)

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawler
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)
 
Use case diagram
Use case diagramUse case diagram
Use case diagram
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)
 
6 java - loop
6  java - loop6  java - loop
6 java - loop
 
4 java - decision
4  java - decision4  java - decision
4 java - decision
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable type
 
2 java - operators
2  java - operators2  java - operators
2 java - operators
 
1 java - data type
1  java - data type1  java - data type
1 java - data type
 
Uta005 lecture3
Uta005 lecture3Uta005 lecture3
Uta005 lecture3
 
Uta005 lecture1
Uta005 lecture1Uta005 lecture1
Uta005 lecture1
 
Uta005 lecture2
Uta005 lecture2Uta005 lecture2
Uta005 lecture2
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protection
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitives
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devices
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devices
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphics
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Último (20)

Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

OS - Deadlock

  • 1. Deadlock Organized By: Vinay Arora Assistant Professor CSED, TU V.A. CSED,TU
  • 2. Disclaimer This is NOT A COPYRIGHT MATERIAL Content has been taken mainly from the following books: Operating Systems Concepts By Silberschatz & Galvin, Operating Systems: Internals and Design Principles By William Stallings www.os-book.com www.cs.jhu.edu/~yairamir/cs418/os2/sld001.htm www.personal.kent.edu/~rmuhamma/OpSystems/os.html http://msdn.microsoft.com/en-us/library/ms685096(VS.85).aspx http://www.computer.howsttuffworks.com/operating-system6.htm http://williamstallings.com/OS/Animations.html Etc… VA. CSED,TU
  • 3. Deadlock – Real Life Scenario VA. CSED,TU
  • 4. System Model Resource types R1, R2, . . ., Rm CPU cycles, memory space, I/O devices Each resource type Ri has Wi instances. Each process utilizes a resource as follows: request use release VA. CSED,TU
  • 5. Deadlock Characterization Mutual Exclusion: only one process at a time can use a resource. Hold and Wait: a process holding at least one resource is waiting to acquire additional resources held by other processes. No Preemption: a resource can be released only voluntarily by the process holding it, after that process has completed its task. Circular Wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0 is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by P2, …, Pn–1 is waiting for a resource that is held by Pn, and P0 is waiting for a resource that is held by P0. VA. CSED,TU
  • 6. RAG A set of vertices V and a set of edges E. V is partitioned into two types: P = {P1, P2, …, Pn}, the set consisting of all the processes in the system. R = {R1, R2, …, Rm}, the set consisting of all resource types in the system. request edge – directed edge P1 → Rj assignment edge – directed edge Rj → Pi VA. CSED,TU
  • 7. Process Resource Type with 4 instances Pi requests instance of Rj Pi Pi is holding an instance of Rj Pi VA. CSED,TU
  • 8. Example - RAG VA. CSED,TU
  • 9. RAG with Deadlock VA. CSED,TU
  • 10. RAG with no Deadlock VA. CSED,TU
  • 11. Basic Facts If graph contains no cycles ⇒ no deadlock. If graph contains a cycle ⇒ if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock. VA. CSED,TU
  • 12. Deadlock Prevention Mutual Exclusion – not required for sharable resources; must hold for non sharable resources. Hold and Wait – must guarantee that whenever a process requests a resource, it does not hold any other resources. Require process to request and be allocated all its resources before it begins execution, or allow process to request resources only when the process has none. Low resource utilization; starvation possible. VA. CSED,TU
  • 13. No Preemption – If a process that is holding some resources requests another resource that cannot be immediately allocated to it, then all resources currently being held are released. Preempted resources are added to the list of resources for which the process is waiting. Process will be restarted only when it can regain its old resources, as well as the new ones that it is requesting. Circular Wait – impose a total ordering of all resource types, and require that each process requests resources in an increasing order of enumeration. VA. CSED,TU
  • 14. Safe, Unsafe & Deadlock State VA. CSED,TU
  • 15. Banker’s Algorithm – Safety Algo. 1. Let Work and Finish be vectors of length m and n, respectively. Initialize Work = Available and Finish[i]=False for i=0,1,2……,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. VA. CSED,TU
  • 16. Banker’s Algo. – Resource Request Algo. 1. If Requesti < Needi, go to step 2. Otherwise, raise an error condition, since the process has exceeded its maximum claim. 2. If Requesti < Available, go to step 3. Otherwise, Pi must wait, since the resources are not available. 3. Have the system pretend to have allocated the requested resources to process Pi by modifying the state as follows: Available = Available – Requesti Allocationi =Allocationi + Requesti Needi = Needi - Requesti VA. CSED,TU
  • 17. Problem Statement Allocation Max Available A B C A B C A B C P0 0 1 0 7 5 3 3 3 2 P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 Request1 = (1,0,2) After Calculating the Matrix Execute for below mentioned Requests Request0 = (0,2,0) Request4 = (3,3,0) VA. CSED,TU
  • 18. Deadlock Detection Allow system to enter deadlock state Detection algorithm Recovery scheme VA. CSED,TU
  • 19. Single Instance of each Resource Type Maintain wait-for graph Nodes are processes. Pi → Pj if Pi is waiting for Pj. Periodically invoke an algorithm that searches for a cycle in the graph. VA. CSED,TU
  • 20. RAG & Wait For Graph VA. CSED,TU
  • 21. Several Instances of resource Type Available: A vector of length m indicates the number of available resources of each type. Allocation: An n x m matrix defines the number of resources of each type currently allocated to each process. Request: An n x m matrix indicates the current request of each process. If Request [ij] = k, then process Pi is requesting k more instances of resource type. Rj. VA. CSED,TU
  • 22. Deadlock Detection 1. Let Work and Finish be vectors of length m and n, respectively. Initialize Work = Available. For i=0,1,2……,n-1, if Allocationi Not equal to ZERO, then Finish[i] = False; Otherwise,Finish[i] = True 2. Find an index i such that both Finish[i] = = False 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, then the system is in Deadlock State. VA. CSED,TU
  • 23. Problem Statement Allocation Request Available A B C A B C A B C P0 0 1 0 0 0 0 0 0 0 P1 2 0 0 2 0 2 P2 3 0 3 0 0 0 P3 2 1 1 1 0 0 P4 0 0 2 0 0 2 Request A B C 0 0 0 2 0 2 0 0 1 1 0 0 0 0 2 VA. CSED,TU
  • 24. Recovery from Deadlock – Process Termination Abort all deadlocked processes. Abort one process at a time until the deadlock cycle is eliminated. In which order should we choose to abort? Priority of the process. How long process has computed, and how much longer to completion. Resources the process has used. Resources process needs to complete. How many processes will need to be terminated. VA. CSED,TU
  • 25. Recovery from Deadlock – Resource Preemption Selecting a victim – minimize cost. Rollback – return to some safe state, restart process for that state. Starvation – same process may always be picked as victim, include number of rollback in cost factor. VA. CSED,TU
  • 26. Thnx… VA. CSED,TU