0% found this document useful (0 votes)
18 views

Finals_Introduction-of-Deadlock-in-Operating-System

Uploaded by

aidanavales1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Finals_Introduction-of-Deadlock-in-Operating-System

Uploaded by

aidanavales1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction of Deadlock in Operating System

A deadlock is a situation where a set of processes is blocked because each process is


holding a resource and waiting for another resource acquired by some other
process. In this article, we will discuss deadlock, its necessary conditions, etc. in
detail.

What is Deadlock?
Deadlock is a situation in computing where two or more processes are unable to
proceed because each is waiting for the other to release resources. Key concepts
include mutual exclusion, resource holding, circular wait, and no preemption.
Consider an example when two trains are coming toward each other on the same
track and there is only one track, none of the trains can move once they are in front
of each other. This is a practical example of deadlock.

How Does Deadlock occur in the Operating System?


Before going into detail about how deadlock occurs in the Operating System, let’s
first discuss how the Operating System uses the resources present. A process in an
operating system uses resources in the following way.
 Requests a resource
 Use the resource
 Releases the resource

A situation occurs in operating systems when there are two or more processes that
hold some resources and wait for resources held by other(s). For example, in the
below diagram, Process 1 is holding Resource 1 and waiting for resource 2 which is
acquired by process 2, and process 2 is waiting for resource 1.

Necessary Conditions for Deadlock in OS


Deadlock can arise if the following four conditions hold simultaneously (Necessary
Conditions)
 Mutual Exclusion: Two or more resources are non-shareable (Only one process
can use at a time).
 Hold and Wait: A process is holding at least one resource and waiting for
resources.
 No Preemption: A resource cannot be taken from a process unless the process
releases the resource.
 Circular Wait: A set of processes waiting for each other in circular form.

What is Deadlock Detection?
Deadlock detection is a process in computing where the system checks if there are
any sets of processes that are stuck waiting for each other indefinitely, preventing
them from moving forward. In simple words, deadlock detection is the process of
finding out whether any process are stuck in loop or not. There are several
algorithms like
 Resource Allocation Graph
 Banker’s Algorithm
These algorithms helps in detection of deadlock in Operating System.
What are the Methods For Handling Deadlock?
There are three ways to handle deadlock
 Deadlock Prevention or Avoidance
 Deadlock Recovery
 Deadlock Ignorance

Deadlock Prevention or Avoidance


Deadlock Prevention and Avoidance is the one of the methods for handling
deadlock. First, we will discuss Deadlock Prevention, then Deadlock Avoidance.

What is Deadlock Prevention?

In deadlock prevention the aim is to not let full-fill one of the required condition of
the deadlock. This can be done by this method:
(i) Mutual Exclusion
We only use the Lock for the non-share-able resources and if the resource is
share- able (like read only file) then we not use the locks here. That ensure that in
case of share -able resource , multiple process can access it at same time. Problem-
Here the problem is that we can only do it in case of share-able resources but in case
of no-share-able resources like printer , we have to use Mutual exclusion.
(ii) Hold and Wait
To ensure that Hold and wait never occurs in the system, we must guarantee that
whenever process request for resource , it does not hold any other resources.
 we can provide the all resources to the process that is required for it’s execution
before starting it’s execution . problem – for example if there are three resource
that is required by a process and we have given all that resource before starting
execution of process then there might be a situation that initially we required
only two resource and after one hour we want third resources and this will cause
starvation for the another process that wants this resources and in that waiting
time that resource can allocated to other process and complete their execution.
 We can ensure that when a process request for any resources that time the
process does not hold any other resources. Ex- Let there are three resources
DVD, File and Printer . First the process request for DVD and File for the
copying data into the file and let suppose it is going to take 1 hour and after it the
process free all resources then again request for File and Printer to print that file.
(iii) No Preemption
If a process is holding some resource and requestion other resources that are
acquired and these resource are not available immediately then the resources that
current process is holding are preempted. After some time process again request for
the old resources and other required resources to re-start.
For example – Process p1 have resource r1 and requesting for r2 that is hold by
process p2. then process p1 preempt r1 and after some time it try to restart by
requesting both r1 and r2 resources.
Problem – This can cause the Live Lock Problem .
Live Lock : Live lock is the situation where two or more processes continuously
changing their state in response to each other without making any real progress.
Example:
 suppose there are two processes p1 and p2 and two resources r1 and r2.
 Now, p1 acquired r1 and need r2 & p2 acquired r2 and need r1.
 so according to above method- Both p1 and p2 detect that they can’t acquire
second resource, so they release resource that they are holding and then try again.
 continuous cycle- p1 again acquired r1 and requesting to r2 p2 again acquired r2
and requesting to r1 so there is no overall progress still process are changing
there state as they preempt resources and then again holding them. This the
situation of Live Lock.
(iv) Circular Wait:
To remove the circular wait in system we can give the ordering of resources in
which a process needs to acquire.
Ex: If there are process p1 and p2 and resources r1 and r2 then we can fix the
resource acquiring order like the process first need to acquire resource r1 and then
resource r2. so the process that acquired r1 will be allowed to acquire r2 , other
process needs to wait until r1 is free.
This is the Deadlock prevention methods but practically only fourth method is used
as all other three condition removal method have some disadvantages with them .

What is Deadlock Avoidance?

Avoidance is kind of futuristic. By using the strategy of “Avoidance”, we have to


make an assumption. We need to ensure that all information about resources that the
process will need is known to us before the execution of the process. We use
Banker’s algorithm (Which is in turn a gift from Dijkstra) to avoid deadlock.
In prevention and avoidance, we get the correctness of data but performance
decreases.
What is Deadlock Recovery?
If Deadlock prevention or avoidance is not applied to the software then we can
handle this by deadlock detection and recovery. which consist of two phases:
1. In the first phase, we examine the state of the process and check whether there is
a deadlock or not in the system.
2. If found deadlock in the first phase then we apply the algorithm for recovery of
the deadlock.
In Deadlock detection and recovery, we get the correctness of data but performance
decreases.

Methods of Deadlock Recovery

There are several Deadlock Recovery Techniques:


 Manual Intervention
 Automatic Recovery
 Process Termination
 Resource Preemption
1. Manual Intervention

When a deadlock is detected, one option is to inform the operator and let them
handle the situation manually. While this approach allows for human judgment and
decision-making, it can be time-consuming and may not be feasible in large-scale
systems.

2. Automatic Recovery

An alternative approach is to enable the system to recover from deadlock


automatically. This method involves breaking the deadlock cycle by either aborting
processes or preempting resources. Let’s delve into these strategies in more detail.

3. Process Termination

 Abort all Deadlocked Processes


o This approach breaks the deadlock cycle, but it comes at a significant cost.
The processes that were aborted may have executed for a considerable
amount of time, resulting in the loss of partial computations. These
computations may need to be recomputed later.
 Abort one process at a time
o Instead of aborting all deadlocked processes simultaneously, this strategy
involves selectively aborting one process at a time until the deadlock cycle
is eliminated. However, this incurs overhead as a deadlock-detection
algorithm must be invoked after each process termination to determine if
any processes are still deadlocked.
o Factors for choosing the termination order:
o The process’s priority
o Completion time and the progress made so far
o Resources consumed by the process
o Resources required to complete the process
o Number of processes to be terminated
o Process type (interactive or batch)

4. Resource Preemption

 Selecting a Victim
o Resource preemption involves choosing which resources and processes
should be preempted to break the deadlock. The selection order aims to
minimize the overall cost of recovery. Factors considered for victim
selection may include the number of resources held by a deadlocked
process and the amount of time the process has consumed.
 Rollback
o If a resource is preempted from a process, the process cannot continue its
normal execution as it lacks the required resource. Rolling back the process
to a safe state and restarting it is a common approach. Determining a safe
state can be challenging, leading to the use of total rollback, where the
process is aborted and restarted from scratch.
 Starvation Prevention
o To prevent resource starvation, it is essential to ensure that the same
process is not always chosen as a victim. If victim selection is solely based
on cost factors, one process might repeatedly lose its resources and never
complete its designated task. To address this, it is advisable to limit the
number of times a process can be chosen as a victim, including the number
of rollbacks in the cost factor.

What is Deadlock Ignorance?


If a deadlock is very rare, then let it happen and reboot the system. This is the
approach that both Windows and UNIX take. we use the ostrich algorithm for
deadlock ignorance.
In Deadlock, ignorance performance is better than the above two methods but the
correctness of data is not there.

Safe State

A safe state can be defined as a state in which there is no deadlock. It is achievable


if:
 If a process needs an unavailable resource, it may wait until the same has been
released by a process to which it has already been allocated. if such a sequence
does not exist, it is an unsafe state.
 All the requested resources are allocated to the process.
Aspect Deadlock Starvation

A condition where two or more A condition where a process is


processes are blocked forever, perpetually denied necessary
Definition
each waiting for a resource held resources, despite resources
by another. being available.

Resources are available but are


Resource Resources are held by processes
continuously allocated to other
Availability involved in the deadlock.
processes.

Circular dependency between Continuous preference or


processes, where each process priority given to other
Cause
is waiting for a resource from processes, causing a process to
another. wait indefinitely.

Requires intervention, such as


Can be mitigated by adjusting
aborting processes or
Resolution scheduling policies to ensure
preempting resources to break
fair resource allocation.
the cycle.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy