Unit 3 – Part 2
Deadlock
Methods for handling deadlock
There are three ways to handle deadlock
1) Deadlock prevention or avoidance:
The idea is to not let the system into deadlock state.
One can zoom into each category individually, Prevention
is done by negating one of above mentioned necessary
conditions for deadlock.
Avoidance is kind of futuristic in nature. By using strategy
of “Avoidance”, we have to make an assumption. We need
to ensure that all information about resources which
process WILL need are known to us prior to execution of
the process.
2) Deadlock detection and recovery: Let deadlock occur,
then do preemption to handle it once occurred.
3) Ignore the problem all together: If deadlock is very
rare, then let it happen and reboot the system. This is the
approach that both Windows and UNIX take.
Deadlock Detection
A deadlock can be detected by a resource scheduler as it keeps
track of all the resources that are allocated to different
processes. After a deadlock is detected, it can be resolved using
the following methods.
All the processes that are involved in the deadlock are
terminated. This is not a good approach as all the progress
made by the processes is destroyed.
Resources can be preempted from some processes and given to
others till the deadlock is resolved.
If resources have single instance:
In this case for Deadlock detection we can run an algorithm to
check for cycle in the Resource Allocation Graph. Presence of
cycle in the graph is the sufficient condition for deadlock.
In the diagram, resource 1 and resource 2 have single instances.
There is a cycle R1 → P1 → R2 → P2. So, Deadlock is Confirmed.
Deadlock Detection
If there are multiple instances of resources:
Detection of the cycle is necessary but not sufficient
condition for deadlock detection, in this case, the
system may or may not be in deadlock varies
according to different situations.
Deadlock Recovery
A traditional operating system such as Windows doesn’t deal
with deadlock recovery as it is time and space consuming
process. Real-time operating systems use Deadlock recovery.
Recovery method
Killing the process: killing all the process involved in the
deadlock. Killing process one by one. After killing each process
check for deadlock again keep repeating the process till
system recover from deadlock.
Resource Preemption: Resources are preempted from the
processes involved in the deadlock, preempted resources are
allocated to other processes so that there is a possibility of
recovering the system from deadlock. In this case, the system
goes into starvation.
Deadlock Avoidance
Deadlock avoidance merely works to avoid deadlock; it does not totally
prevent it. The basic idea here is to allocate resources only if the resulting
global state is a safe state.
In other words, unsafe states are avoided, meaning that deadlock is avoided
as well.
• When a process requests a resource, even if it is available, it is not
immediately allocated to the process. Instead the
systems assumes (pretends) it is so allocated.
• With this assumption, along with advance knowledge of all the resources
needed for all the processes, the system performs some analysis to
decide whether or not granting the request is safe.
• If the request is safe, the resource is granted to the requesting process.
Otherwise, the resource is not given to the process at this time.
This type of algorithm requires each site to have access to a global state
(requiring too much storage and communication). Also the checking of the
involved data structures must be done in a mutually exclusive fashion. With
many sites and resources, it just takes too long.
Deadlock avoidance can be done with Banker’s Algorithm.
Banker’s Algorithm
Bankers’s Algorithm is resource allocation and deadlock avoidance
algorithm which test all the request made by processes for resources, it
checks for the safe state, if after granting request system remains in the
safe state it allows the request and if there is no safe state it doesn’t allow
the request made by the process.
Inputs to Banker’s Algorithm:
• Max need of resources by each process.
• Currently allocated resources by each process.
• Max free available resources in the system.
The request will only be granted under the below condition:
• If the request made by the process is less than equal to max need to that
process.
• If the request made by the process is less than equal to the freely
available resource in the system.
Deadlock Prevention
It is very important to prevent a deadlock before it
can occur. So, the system checks each transaction
before it is executed to make sure it does not lead to
deadlock. If there is even a slight chance that a
transaction may lead to deadlock in the future, it is
never allowed to execute
Deadlock Prevention
This strategy involves designing a system that
violates one of the four necessary conditions
required for the occurrence of deadlock.
This ensures that the system remains free from the
deadlock.
The various conditions of deadlock occurrence may
be violated as-
• Eliminate Mutual Exclusion
• Eliminate Hold and Wait
• Eliminate No Pre-emption
• Eliminate Circular Wait
Deadlock Prevention
1- Eliminate Mutual Exclusion
To violate this condition, all the system resources
must be such that they can be used in a shareable
mode.
In a system, there are always some resources which
are mutually exclusive by nature.
So, this condition can not be violated.
Deadlock Prevention
2- Eliminate Hold and Wait
This condition can be violated in the following ways-
Approach-01:
In this approach,
• A process has to first request for all the resources it requires for
execution.
• Once it has acquired all the resources, only then it can start its execution.
• This approach ensures that the process does not hold some resources and
wait for other resources.
Drawbacks-
The drawbacks of this approach are-
• It is less efficient.
• It is not implementable since it is not possible to predict in advance which
resources will be required during execution.
Deadlock Prevention
Approach-02:
In this approach,
• A process is allowed to acquire the resources it desires at the
current moment.
• After acquiring the resources, it start its execution.
• Now before making any new request, it has to compulsorily
release all the resources that it holds currently.
• This approach is efficient and implementable.
Approach-03:
In this approach,
• A timer is set after the process acquires any resource.
• After the timer expires, a process has to compulsorily release the
resource.
Deadlock Prevention
3-Eliminate No Pre-emption
This condition can by violated by forceful pre-emption.
• Consider a process is holding some resources and
request other resources that can not be immediately
allocated to it.
• Then, by forcefully pre-empting the currently held
resources, the condition can be violated.
• A process is allowed to forcefully pre-empt the
resources possessed by some other process only if It is
a high priority process or a system process. The victim
process is in the waiting state.
Deadlock Prevention
4-Eliminate Circular Wait
This condition can be violated by not allowing the processes to wait for
resources in a cyclic manner.
To violate this condition, the following approach is followed-
Approach
A numerical number is assigned to every resource.
Each process is allowed to request for the resources either in only
increasing or only decreasing order of the resource number.
In case increasing order is followed, if a process requires a lesser number
resource, then it must release all the resources having larger number and
vice versa.
This approach is the most practical approach and implementable.
However, this approach may cause starvation but will never lead to
deadlock.

More Related Content

PPTX
deadlock handling
PPTX
Deadlock Slides
PDF
Deadlock in Distributed Systems
PDF
Deadlock in distribute system by saeed siddik
DOCX
Deadlock detection
DOCX
Os case study word
PPTX
operating system
PPTX
operating system
deadlock handling
Deadlock Slides
Deadlock in Distributed Systems
Deadlock in distribute system by saeed siddik
Deadlock detection
Os case study word
operating system
operating system

What's hot (20)

PPTX
Deadlocks
PDF
Distributed deadlock
PPTX
Deadlocks
PDF
deadlock prevention
PDF
Methods for handling deadlocks
PPTX
Operating system - Deadlock
PPTX
Deadlock- Operating System
PPS
Deadlock
PPTX
Deadlock
PPTX
Deadlock Avoidance in Operating System
PDF
ikh311-05
PDF
Deadlock
PPTX
DeadLock in Operating-Systems
PPTX
Deadlock and memory management -- Operating System
PPTX
Deadlock in Operating System
PDF
Deadlocks
PPTX
Deadlock Presentation
PPTX
Deadlock ppt
PPT
Chapter06
Deadlocks
Distributed deadlock
Deadlocks
deadlock prevention
Methods for handling deadlocks
Operating system - Deadlock
Deadlock- Operating System
Deadlock
Deadlock
Deadlock Avoidance in Operating System
ikh311-05
Deadlock
DeadLock in Operating-Systems
Deadlock and memory management -- Operating System
Deadlock in Operating System
Deadlocks
Deadlock Presentation
Deadlock ppt
Chapter06
Ad

Similar to Unit 3 part 2(DEADLOCK) (20)

PPTX
Deadlocks and Deadlock Detection Other Issues
PPTX
4.3 Deadlock [Autosaved].pptx
PPTX
DEADLOCK PREVENTION AND AVOIDANCE.pptx
PDF
“Understanding Distributed Deadlocks: Causes, Detection
PPTX
DistributedDeadlock on distriburtedNetwork.pptx
PPTX
Deadlock
PPTX
OS 7.pptx
PPTX
3.6 Deadlock-operating system unit 3.pptx
PPTX
Deadlock
PDF
osvishal-160830131208 (1).pdf
PPTX
Algorithm 4Chapter Four- Deadlock (5).pptx
PPTX
Lecture 4 Deadlocks in operating systems.pptx
PPTX
Untitled presentation.pptx os ppt deadlock prevention
PPTX
deadlock in operating system in osss.pptx
PPTX
deadlock in operating system ( os ).pptx
PPTX
dead-locks and deadlock handling in operating systems.pptx
PPT
Deadlock in operating systems
PPTX
Unit iv: Deadlocks
Deadlocks and Deadlock Detection Other Issues
4.3 Deadlock [Autosaved].pptx
DEADLOCK PREVENTION AND AVOIDANCE.pptx
“Understanding Distributed Deadlocks: Causes, Detection
DistributedDeadlock on distriburtedNetwork.pptx
Deadlock
OS 7.pptx
3.6 Deadlock-operating system unit 3.pptx
Deadlock
osvishal-160830131208 (1).pdf
Algorithm 4Chapter Four- Deadlock (5).pptx
Lecture 4 Deadlocks in operating systems.pptx
Untitled presentation.pptx os ppt deadlock prevention
deadlock in operating system in osss.pptx
deadlock in operating system ( os ).pptx
dead-locks and deadlock handling in operating systems.pptx
Deadlock in operating systems
Unit iv: Deadlocks
Ad

More from WajeehaBaig (6)

PDF
File system
PDF
Unit 2 part 2(Process)
PDF
Unit 2 part 1(Process)
PDF
lecture 1 (Part 2) kernal and its categories
PDF
Unit 3 part 1(DEADLOCK)
PDF
lecture 1 (Introduction to Operating System.)
File system
Unit 2 part 2(Process)
Unit 2 part 1(Process)
lecture 1 (Part 2) kernal and its categories
Unit 3 part 1(DEADLOCK)
lecture 1 (Introduction to Operating System.)

Recently uploaded (20)

PPT
Programmable Logic Controller PLC and Industrial Automation
PDF
Principles of operation, construction, theory, advantages and disadvantages, ...
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
Solar energy pdf of gitam songa hemant k
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PPTX
Wireless sensor networks (WSN) SRM unit 2
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
Micro 3 New.ppt.pdf tools the laboratory the method
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PPTX
AI-Reporting for Emerging Technologies(BS Computer Engineering)
PPTX
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
PPTX
DATA STRCUTURE LABORATORY -BCSL305(PRG1)
PPTX
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
PPTX
Environmental studies, Moudle 3-Environmental Pollution.pptx
PPTX
chapter 1.pptx dotnet technology introduction
PPTX
CNS - Unit 1 (Introduction To Computer Networks) - PPT (2).pptx
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PPTX
Principal presentation for NAAC (1).pptx
PDF
IAE-V2500 Engine for Airbus Family 319/320
Programmable Logic Controller PLC and Industrial Automation
Principles of operation, construction, theory, advantages and disadvantages, ...
Cryptography and Network Security-Module-I.pdf
Solar energy pdf of gitam songa hemant k
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
Wireless sensor networks (WSN) SRM unit 2
Micro1New.ppt.pptx the mai themes of micfrobiology
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Micro 3 New.ppt.pdf tools the laboratory the method
An investigation of the use of recycled crumb rubber as a partial replacement...
AI-Reporting for Emerging Technologies(BS Computer Engineering)
BBOC407 BIOLOGY FOR ENGINEERS (CS) - MODULE 1 PART 1.pptx
DATA STRCUTURE LABORATORY -BCSL305(PRG1)
Module1.pptxrjkeieuekwkwoowkemehehehrjrjrj
Environmental studies, Moudle 3-Environmental Pollution.pptx
chapter 1.pptx dotnet technology introduction
CNS - Unit 1 (Introduction To Computer Networks) - PPT (2).pptx
Beginners-Guide-to-Artificial-Intelligence.pdf
Principal presentation for NAAC (1).pptx
IAE-V2500 Engine for Airbus Family 319/320

Unit 3 part 2(DEADLOCK)

  • 1. Unit 3 – Part 2 Deadlock
  • 2. Methods for handling deadlock There are three ways to handle deadlock 1) Deadlock prevention or avoidance: The idea is to not let the system into deadlock state. One can zoom into each category individually, Prevention is done by negating one of above mentioned necessary conditions for deadlock. Avoidance is kind of futuristic in nature. By using strategy of “Avoidance”, we have to make an assumption. We need to ensure that all information about resources which process WILL need are known to us prior to execution of the process. 2) Deadlock detection and recovery: Let deadlock occur, then do preemption to handle it once occurred. 3) Ignore the problem all together: If deadlock is very rare, then let it happen and reboot the system. This is the approach that both Windows and UNIX take.
  • 3. Deadlock Detection A deadlock can be detected by a resource scheduler as it keeps track of all the resources that are allocated to different processes. After a deadlock is detected, it can be resolved using the following methods. All the processes that are involved in the deadlock are terminated. This is not a good approach as all the progress made by the processes is destroyed. Resources can be preempted from some processes and given to others till the deadlock is resolved. If resources have single instance: In this case for Deadlock detection we can run an algorithm to check for cycle in the Resource Allocation Graph. Presence of cycle in the graph is the sufficient condition for deadlock. In the diagram, resource 1 and resource 2 have single instances. There is a cycle R1 → P1 → R2 → P2. So, Deadlock is Confirmed.
  • 4. Deadlock Detection If there are multiple instances of resources: Detection of the cycle is necessary but not sufficient condition for deadlock detection, in this case, the system may or may not be in deadlock varies according to different situations.
  • 5. Deadlock Recovery A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is time and space consuming process. Real-time operating systems use Deadlock recovery. Recovery method Killing the process: killing all the process involved in the deadlock. Killing process one by one. After killing each process check for deadlock again keep repeating the process till system recover from deadlock. Resource Preemption: Resources are preempted from the processes involved in the deadlock, preempted resources are allocated to other processes so that there is a possibility of recovering the system from deadlock. In this case, the system goes into starvation.
  • 6. Deadlock Avoidance Deadlock avoidance merely works to avoid deadlock; it does not totally prevent it. The basic idea here is to allocate resources only if the resulting global state is a safe state. In other words, unsafe states are avoided, meaning that deadlock is avoided as well. • When a process requests a resource, even if it is available, it is not immediately allocated to the process. Instead the systems assumes (pretends) it is so allocated. • With this assumption, along with advance knowledge of all the resources needed for all the processes, the system performs some analysis to decide whether or not granting the request is safe. • If the request is safe, the resource is granted to the requesting process. Otherwise, the resource is not given to the process at this time. This type of algorithm requires each site to have access to a global state (requiring too much storage and communication). Also the checking of the involved data structures must be done in a mutually exclusive fashion. With many sites and resources, it just takes too long.
  • 7. Deadlock avoidance can be done with Banker’s Algorithm. Banker’s Algorithm Bankers’s Algorithm is resource allocation and deadlock avoidance algorithm which test all the request made by processes for resources, it checks for the safe state, if after granting request system remains in the safe state it allows the request and if there is no safe state it doesn’t allow the request made by the process. Inputs to Banker’s Algorithm: • Max need of resources by each process. • Currently allocated resources by each process. • Max free available resources in the system. The request will only be granted under the below condition: • If the request made by the process is less than equal to max need to that process. • If the request made by the process is less than equal to the freely available resource in the system.
  • 8. Deadlock Prevention It is very important to prevent a deadlock before it can occur. So, the system checks each transaction before it is executed to make sure it does not lead to deadlock. If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute
  • 9. Deadlock Prevention This strategy involves designing a system that violates one of the four necessary conditions required for the occurrence of deadlock. This ensures that the system remains free from the deadlock. The various conditions of deadlock occurrence may be violated as- • Eliminate Mutual Exclusion • Eliminate Hold and Wait • Eliminate No Pre-emption • Eliminate Circular Wait
  • 10. Deadlock Prevention 1- Eliminate Mutual Exclusion To violate this condition, all the system resources must be such that they can be used in a shareable mode. In a system, there are always some resources which are mutually exclusive by nature. So, this condition can not be violated.
  • 11. Deadlock Prevention 2- Eliminate Hold and Wait This condition can be violated in the following ways- Approach-01: In this approach, • A process has to first request for all the resources it requires for execution. • Once it has acquired all the resources, only then it can start its execution. • This approach ensures that the process does not hold some resources and wait for other resources. Drawbacks- The drawbacks of this approach are- • It is less efficient. • It is not implementable since it is not possible to predict in advance which resources will be required during execution.
  • 12. Deadlock Prevention Approach-02: In this approach, • A process is allowed to acquire the resources it desires at the current moment. • After acquiring the resources, it start its execution. • Now before making any new request, it has to compulsorily release all the resources that it holds currently. • This approach is efficient and implementable. Approach-03: In this approach, • A timer is set after the process acquires any resource. • After the timer expires, a process has to compulsorily release the resource.
  • 13. Deadlock Prevention 3-Eliminate No Pre-emption This condition can by violated by forceful pre-emption. • Consider a process is holding some resources and request other resources that can not be immediately allocated to it. • Then, by forcefully pre-empting the currently held resources, the condition can be violated. • A process is allowed to forcefully pre-empt the resources possessed by some other process only if It is a high priority process or a system process. The victim process is in the waiting state.
  • 14. Deadlock Prevention 4-Eliminate Circular Wait This condition can be violated by not allowing the processes to wait for resources in a cyclic manner. To violate this condition, the following approach is followed- Approach A numerical number is assigned to every resource. Each process is allowed to request for the resources either in only increasing or only decreasing order of the resource number. In case increasing order is followed, if a process requires a lesser number resource, then it must release all the resources having larger number and vice versa. This approach is the most practical approach and implementable. However, this approach may cause starvation but will never lead to deadlock.