SlideShare a Scribd company logo
1 of 28
Rushdi Shams, Dept of CSE, KUET 1
Operating SystemsOperating Systems
DeadlocksDeadlocks
Version 1.0
Rushdi Shams, Dept of CSE, KUET 2
Definition of Deadlock
When two trains approach each other at crossing,
both shall come to a full stop and neither shall start
up again until the other has gone (Kansas Legislature
for railroads in 1920)
A process requests resources
If the resources are not available at that time, the
process enters into waiting state
It never again change state because resources it
requested are requested by other waiting processes
Rushdi Shams, Dept of CSE, KUET 3
How processes utilize resources
If a system has 2 CPUs, then it is said, the system has
a resource type CPU of 2 instances
A process must request a resource before using it
And it must release after using it
A process may request as many resources as it
requires to carry out its designated task
Number of requesting resources MUST not exceed
the total number of available resources
So, a process utilizes resources with three sequences:
request-use-release
Rushdi Shams, Dept of CSE, KUET 4
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: Process releases resources
voluntarily, you cannot force it.
Circular wait: there exists a set {P0, P1, …, P0} of
waiting processes such that P0is waiting for a resource
that is held by P1, P1 is waiting for a resource that is
held by
Rushdi Shams, Dept of CSE, KUET 5
Resource-Allocation Graph
• 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
Rushdi Shams, Dept of CSE, KUET 6
Resource-Allocation Graph
Process
Resource Type with 4 instances
Pi requests instance of Rj
Pi is holding an instance of Rj Pi
Pi
Rj
Rj
Rushdi Shams, Dept of CSE, KUET 7
Resource Allocation Graph
Rushdi Shams, Dept of CSE, KUET 8
Resource Allocation Graph With A
Deadlock
Rushdi Shams, Dept of CSE, KUET 9
Graph With A Cycle But No
Deadlock
Rushdi Shams, Dept of CSE, KUET 10
Resource Allocation Graph
If graph contains no cycles then no deadlock.
If graph contains a cycle then
if only one instance per resource type, then deadlock.
if several instances per resource type, possibility of
deadlock
Rushdi Shams, Dept of CSE, KUET 11
Methods for handling Deadlocks
We can prevent deadlock- which is still a dream, but
soon have a chance to be real
We can avoid deadlocks- by using protocols, ensuring
that the system will never enter a deadlock state
We can allow the system to enter a deadlock state,
detect it and recover
We can use Ostrich Approach
Rushdi Shams, Dept of CSE, KUET 12
Ostrich Approach
Ostrich is not the name of the inventor of the
approach, it is simply an ostrich.
When ostriches run, they just run!  They pay very
little interest in their surroundings.
It means, Ostrich Algorithm in deadlocks is simply
ignoring the problem… pretending it will never occur.
UNIX runs with this approach.
Rushdi Shams, Dept of CSE, KUET 13
Deadlock Prevention
Mutual Exclusion – not required for sharable
resources; must hold for nonsharable 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.
Rushdi Shams, Dept of CSE, KUET 14
Deadlock Prevention
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.
Rushdi Shams, Dept of CSE, KUET 15
Deadlock Avoidance
• Requires that the system has some additional a priori
information available.
Simplest and most useful model requires that each process
declare the maximum number of resources of each type that it
may need.
The deadlock-avoidance algorithm dynamically examines the
resource-allocation state to ensure that there can never be a
circular-wait condition.
Resource-allocation state is defined by the number of available
and allocated resources, and the maximum demands of the
processes.
Rushdi Shams, Dept of CSE, KUET 16
Safe State
When a process requests an available resource, system must
decide if immediate allocation leaves the system in a safe state.
System is in safe state if there exists a sequence <P1, P2, …, Pn> of
ALL the processes is the systems such that for each Pi, the
resources that Pican still request can be satisfied by currently
available resources + resources held by all the Pj, with j < i.
That is:
If Pi resource needs are not immediately available, then Pi can wait
until all Pj have finished.
When Pj is finished, Pi can obtain needed resources, execute, return
allocated resources, and terminate.
When Pi terminates, Pi+1 can obtain its needed resources, and so on.
Rushdi Shams, Dept of CSE, KUET 17
Basic Facts
If a system is in safe state, then no deadlocks.
If a system is in unsafe state, then possibility of
deadlock.
Avoidance means ensuring that a system will never
enter an unsafe state.
Rushdi Shams, Dept of CSE, KUET 18
Rushdi Shams, Dept of CSE, KUET 19
Deadlock Avoidance: on
Overhead Projector
Rushdi Shams, Dept of CSE, KUET 20
Deadlock Detection & Recovery
 If a system does not impose deadlock prevention
and avoidance mechanism, then a deadlock
situation MAY occur.
 In this circumstance, the system must provide
1. An algorithm to detect deadlock
2. Recovery Mechanism
Rushdi Shams, Dept of CSE, KUET 21
Detection Mechanism 1
We assume that the resource has only one instance.
Maintain wait-for graph (WFG)
Nodes are processes.
Pi → Pj if Pi is waiting for Pj.
Periodically searches for a cycle in the graph. If there
is a cycle, there exists a deadlock.
Rushdi Shams, Dept of CSE, KUET 22
Detection Mechanism 1
Rushdi Shams, Dept of CSE, KUET 23
Detection Mechanism 2
We assume that resources have more than one instance
Five processes P0 through P4;three resource types
A (7 instances), B (2 instances), and C (6 instances).
Snapshot at time T0:
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
Sequence <P0, P2, P3, P4, P1> will result in
Rushdi Shams, Dept of CSE, KUET 24
Detection Algorithm Usage
When should we invoke the detection algorithm?
Depends on two factors-
How often a deadlock is likely to occur?
How many processes will be affected by deadlock when
it happens?
How many processes will be needed to roll back?
Normally detection algorithm is used -
Whenever a request is not served
In every hour
Whenever CPU utilization drops under 40%
Rushdi Shams, Dept of CSE, KUET 25
Recovery Mechanism: Process
Termination
Abort all deadlocked process
Clearly will break the cycle but at a great price
Processes may have computed for a long time and now
the values are going to be lost 
Abort one process at a time until the deadlock cycle is
eliminated
Considerable overhead
Rushdi Shams, Dept of CSE, KUET 26
Recovery Mechanism: Process
Termination
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.
Is process interactive or batch?
Rushdi Shams, Dept of CSE, KUET 27
Recovery Mechanism: 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.
Rushdi Shams, Dept of CSE, KUET 28
Reference
Operating Systems Concept (6th
Edition)
by Silberschatz, Galvin and Gagne

More Related Content

What's hot

Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Shayek Parvez
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemEktaVaswani2
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating systemSara Ali
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Lecture5
Lecture5Lecture5
Lecture5jntu
 

What's hot (11)

Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
Deadlock avoidance (Safe State, Resource Allocation Graph Algorithm)
 
Deadlock Avoidance in Operating System
Deadlock Avoidance in Operating SystemDeadlock Avoidance in Operating System
Deadlock Avoidance in Operating System
 
Deadlock and memory management -- Operating System
Deadlock and memory management -- Operating SystemDeadlock and memory management -- Operating System
Deadlock and memory management -- Operating System
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
Chapter06
Chapter06Chapter06
Chapter06
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
deadlock
deadlockdeadlock
deadlock
 
Lecture5
Lecture5Lecture5
Lecture5
 

Similar to Lecture 11,12 and 13 deadlocks

Similar to Lecture 11,12 and 13 deadlocks (20)

deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Deadlock and Banking Algorithm
Deadlock and Banking AlgorithmDeadlock and Banking Algorithm
Deadlock and Banking Algorithm
 
Deadlock
DeadlockDeadlock
Deadlock
 
Mch7 deadlock
Mch7 deadlockMch7 deadlock
Mch7 deadlock
 
Os unit 4
Os unit 4Os unit 4
Os unit 4
 
Os module 2 d
Os module 2 dOs module 2 d
Os module 2 d
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 
Methods for handling deadlocks
Methods for handling deadlocksMethods for handling deadlocks
Methods for handling deadlocks
 
Deadlock
DeadlockDeadlock
Deadlock
 
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptxosvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
osvzjsjjdndnnssnnsnsndndndnndeadlock.pptx
 
Deadlock in Real Time operating Systempptx
Deadlock in Real Time operating SystempptxDeadlock in Real Time operating Systempptx
Deadlock in Real Time operating Systempptx
 
Distributed Operating System_2
Distributed Operating System_2Distributed Operating System_2
Distributed Operating System_2
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
Sucet os module_3_notes
Sucet os module_3_notesSucet os module_3_notes
Sucet os module_3_notes
 
Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Lecture 11,12 and 13 deadlocks

  • 1. Rushdi Shams, Dept of CSE, KUET 1 Operating SystemsOperating Systems DeadlocksDeadlocks Version 1.0
  • 2. Rushdi Shams, Dept of CSE, KUET 2 Definition of Deadlock When two trains approach each other at crossing, both shall come to a full stop and neither shall start up again until the other has gone (Kansas Legislature for railroads in 1920) A process requests resources If the resources are not available at that time, the process enters into waiting state It never again change state because resources it requested are requested by other waiting processes
  • 3. Rushdi Shams, Dept of CSE, KUET 3 How processes utilize resources If a system has 2 CPUs, then it is said, the system has a resource type CPU of 2 instances A process must request a resource before using it And it must release after using it A process may request as many resources as it requires to carry out its designated task Number of requesting resources MUST not exceed the total number of available resources So, a process utilizes resources with three sequences: request-use-release
  • 4. Rushdi Shams, Dept of CSE, KUET 4 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: Process releases resources voluntarily, you cannot force it. Circular wait: there exists a set {P0, P1, …, P0} of waiting processes such that P0is waiting for a resource that is held by P1, P1 is waiting for a resource that is held by
  • 5. Rushdi Shams, Dept of CSE, KUET 5 Resource-Allocation Graph • 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
  • 6. Rushdi Shams, Dept of CSE, KUET 6 Resource-Allocation Graph Process Resource Type with 4 instances Pi requests instance of Rj Pi is holding an instance of Rj Pi Pi Rj Rj
  • 7. Rushdi Shams, Dept of CSE, KUET 7 Resource Allocation Graph
  • 8. Rushdi Shams, Dept of CSE, KUET 8 Resource Allocation Graph With A Deadlock
  • 9. Rushdi Shams, Dept of CSE, KUET 9 Graph With A Cycle But No Deadlock
  • 10. Rushdi Shams, Dept of CSE, KUET 10 Resource Allocation Graph If graph contains no cycles then no deadlock. If graph contains a cycle then if only one instance per resource type, then deadlock. if several instances per resource type, possibility of deadlock
  • 11. Rushdi Shams, Dept of CSE, KUET 11 Methods for handling Deadlocks We can prevent deadlock- which is still a dream, but soon have a chance to be real We can avoid deadlocks- by using protocols, ensuring that the system will never enter a deadlock state We can allow the system to enter a deadlock state, detect it and recover We can use Ostrich Approach
  • 12. Rushdi Shams, Dept of CSE, KUET 12 Ostrich Approach Ostrich is not the name of the inventor of the approach, it is simply an ostrich. When ostriches run, they just run!  They pay very little interest in their surroundings. It means, Ostrich Algorithm in deadlocks is simply ignoring the problem… pretending it will never occur. UNIX runs with this approach.
  • 13. Rushdi Shams, Dept of CSE, KUET 13 Deadlock Prevention Mutual Exclusion – not required for sharable resources; must hold for nonsharable 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.
  • 14. Rushdi Shams, Dept of CSE, KUET 14 Deadlock Prevention 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.
  • 15. Rushdi Shams, Dept of CSE, KUET 15 Deadlock Avoidance • Requires that the system has some additional a priori information available. Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need. The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition. Resource-allocation state is defined by the number of available and allocated resources, and the maximum demands of the processes.
  • 16. Rushdi Shams, Dept of CSE, KUET 16 Safe State When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. System is in safe state if there exists a sequence <P1, P2, …, Pn> of ALL the processes is the systems such that for each Pi, the resources that Pican still request can be satisfied by currently available resources + resources held by all the Pj, with j < i. That is: If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished. When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. When Pi terminates, Pi+1 can obtain its needed resources, and so on.
  • 17. Rushdi Shams, Dept of CSE, KUET 17 Basic Facts If a system is in safe state, then no deadlocks. If a system is in unsafe state, then possibility of deadlock. Avoidance means ensuring that a system will never enter an unsafe state.
  • 18. Rushdi Shams, Dept of CSE, KUET 18
  • 19. Rushdi Shams, Dept of CSE, KUET 19 Deadlock Avoidance: on Overhead Projector
  • 20. Rushdi Shams, Dept of CSE, KUET 20 Deadlock Detection & Recovery  If a system does not impose deadlock prevention and avoidance mechanism, then a deadlock situation MAY occur.  In this circumstance, the system must provide 1. An algorithm to detect deadlock 2. Recovery Mechanism
  • 21. Rushdi Shams, Dept of CSE, KUET 21 Detection Mechanism 1 We assume that the resource has only one instance. Maintain wait-for graph (WFG) Nodes are processes. Pi → Pj if Pi is waiting for Pj. Periodically searches for a cycle in the graph. If there is a cycle, there exists a deadlock.
  • 22. Rushdi Shams, Dept of CSE, KUET 22 Detection Mechanism 1
  • 23. Rushdi Shams, Dept of CSE, KUET 23 Detection Mechanism 2 We assume that resources have more than one instance Five processes P0 through P4;three resource types A (7 instances), B (2 instances), and C (6 instances). Snapshot at time T0: 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 Sequence <P0, P2, P3, P4, P1> will result in
  • 24. Rushdi Shams, Dept of CSE, KUET 24 Detection Algorithm Usage When should we invoke the detection algorithm? Depends on two factors- How often a deadlock is likely to occur? How many processes will be affected by deadlock when it happens? How many processes will be needed to roll back? Normally detection algorithm is used - Whenever a request is not served In every hour Whenever CPU utilization drops under 40%
  • 25. Rushdi Shams, Dept of CSE, KUET 25 Recovery Mechanism: Process Termination Abort all deadlocked process Clearly will break the cycle but at a great price Processes may have computed for a long time and now the values are going to be lost  Abort one process at a time until the deadlock cycle is eliminated Considerable overhead
  • 26. Rushdi Shams, Dept of CSE, KUET 26 Recovery Mechanism: Process Termination 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. Is process interactive or batch?
  • 27. Rushdi Shams, Dept of CSE, KUET 27 Recovery Mechanism: 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.
  • 28. Rushdi Shams, Dept of CSE, KUET 28 Reference Operating Systems Concept (6th Edition) by Silberschatz, Galvin and Gagne