SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 

La actualidad más candente (20)

7 Deadlocks
7 Deadlocks7 Deadlocks
7 Deadlocks
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
deadlock handling
deadlock handlingdeadlock handling
deadlock handling
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Deadlock
DeadlockDeadlock
Deadlock
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Deadlocks
 Deadlocks Deadlocks
Deadlocks
 
CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2CS6401 OPERATING SYSTEMS Unit 2
CS6401 OPERATING SYSTEMS Unit 2
 
Deadlock
DeadlockDeadlock
Deadlock
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
 
process creation OS
process creation OSprocess creation OS
process creation OS
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
 
Deadlock in Distributed Systems
Deadlock in Distributed SystemsDeadlock in Distributed Systems
Deadlock in Distributed Systems
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Segmentation in operating systems
Segmentation in operating systemsSegmentation in operating systems
Segmentation in operating systems
 

Similar 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
 

Similar 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
 

Más 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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . 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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.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
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

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