SlideShare a Scribd company logo
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

More Related Content

What's hot

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अनिकेत चौधरी
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating systemAli Haider
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocksA. S. M. Shafi
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidancewahab13
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDHIVYADEVAKI
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & preventionIkhtiarUddinShaHin
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating SystemRajan Shah
 
Deadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbianDeadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbiansaad symbian
 
Os case study word
Os case study wordOs case study word
Os case study wordDhol Yash
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OSMsAnita2
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systemstotallooser
 

What's hot (20)

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
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Deadlock
DeadlockDeadlock
Deadlock
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Deadlock detection & prevention
Deadlock detection & preventionDeadlock detection & prevention
Deadlock detection & prevention
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
Deadlock- Operating System
Deadlock- Operating SystemDeadlock- Operating System
Deadlock- Operating System
 
Deadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbianDeadlock detection and recovery by saad symbian
Deadlock detection and recovery by saad symbian
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Os case study word
Os case study wordOs case study word
Os case study word
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Deadlock
DeadlockDeadlock
Deadlock
 
Dead Lock In Operating Systems
Dead Lock In Operating SystemsDead Lock In Operating Systems
Dead Lock In Operating Systems
 

Similar to OS - Deadlock

Similar to 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
 
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
 
6. Deadlock.ppt
6. Deadlock.ppt6. Deadlock.ppt
6. Deadlock.ppt
 

More from vinay arora

Search engine and web crawler
Search engine and web crawlerSearch engine and web crawler
Search engine and web crawlervinay arora
 
Use case diagram (airport)
Use case diagram (airport)Use case diagram (airport)
Use case diagram (airport)vinay arora
 
Use case diagram
Use case diagramUse case diagram
Use case diagramvinay arora
 
Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)Lab exercise questions (AD & CD)
Lab exercise questions (AD & CD)vinay arora
 
SEM - UML (1st case study)
SEM - UML (1st case study)SEM - UML (1st case study)
SEM - UML (1st case study)vinay arora
 
4 java - decision
4  java - decision4  java - decision
4 java - decisionvinay arora
 
3 java - variable type
3  java - variable type3  java - variable type
3 java - variable typevinay arora
 
2 java - operators
2  java - operators2  java - operators
2 java - operatorsvinay arora
 
1 java - data type
1  java - data type1  java - data type
1 java - data typevinay arora
 
Security & Protection
Security & ProtectionSecurity & Protection
Security & Protectionvinay arora
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronizationvinay arora
 
CG - Output Primitives
CG - Output PrimitivesCG - Output Primitives
CG - Output Primitivesvinay arora
 
CG - Display Devices
CG - Display DevicesCG - Display Devices
CG - Display Devicesvinay arora
 
CG - Input Output Devices
CG - Input Output DevicesCG - Input Output Devices
CG - Input Output Devicesvinay arora
 
CG - Introduction to Computer Graphics
CG - Introduction to Computer GraphicsCG - Introduction to Computer Graphics
CG - Introduction to Computer Graphicsvinay arora
 
C Prog. - Strings (Updated)
C Prog. - Strings (Updated)C Prog. - Strings (Updated)
C Prog. - Strings (Updated)vinay arora
 

More from 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)
 

Recently uploaded

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfQucHHunhnh
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxShibin Azad
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online PresentationGDSCYCCE
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxCapitolTechU
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resourcesdimpy50
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXMIRIAMSALINAS13
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
Gyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptxGyanartha SciBizTech Quiz slideshare.pptx
Gyanartha SciBizTech Quiz slideshare.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 

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