Understanding Deadlocks in Operating Systems: Prevention and Recovery

Verified

Added on  2019/10/18

|9
|2687
|326
Essay
AI Summary
This essay delves into the concept of deadlocks within operating systems, a critical issue in modern computing. It begins with a foundational overview of operating systems, setting the stage for a detailed explanation of deadlocks. The essay defines deadlocks as a frequent problem in multiprocessing environments, where processes contend for shared resources, leading to system stagnation. It explores the conditions that cause deadlocks: mutual exclusion, hold and wait, non-preemption, and circular wait, providing clear explanations and examples for each. Furthermore, the essay discusses various methods for handling deadlocks, including prevention, avoidance, and detection with recovery. Deadlock prevention involves eliminating one or more of the necessary conditions, while avoidance focuses on ensuring a safe state. Detection and recovery involve identifying deadlocks and breaking them by terminating processes or preempting resources. The essay underscores the importance of understanding and managing deadlocks to ensure efficient and reliable system performance.
Document Page
A deadlock in the Operating System is a known phenomenon in the tech-savvy world. In the
blog, the extensive idea about what deadlocks are in the Operating System will be discussed.
But before that, we shall have a quick and brief understanding of what an operating system is.
You can only have a clear idea about deadlocks if you can have the detailed knowledge about
the operating system where it works. This blog will help in understanding the concept to those
who are already enriched about the basic tech knowledge. Besides this, it will also help those
who are willing to gain some insight into this topic from beginning.
An operating system, in general, refers to the consolidated set of software which is present in a
computer. When the system of hardware and software work together they result in providing the
required service to the end consumer. The concept of an operating system is made clear. Now,
some examples shall be put forward to relate it in the real world and clarify any other query. The
common examples of Operating Systems are Microsoft Windows, Apple iOS, Google's Android
OS, Apple macOS, and Linux OS. So, let’s begin with the definition of deadlock and the types of
deadlock and so forth.
Deadlock: A Frequent Problem for Operators
Deadlock is nowadays a very frequent problem in multiprocessing. It occurs when numerous
processes share a specific resource famous as software or soft lock. The interaction among
various processes as well as resources can cause problems known as deadlock. It is a non-
deterministic bug that can occur in a parallel system. These kinds of bugs are difficult to check
and debug. A deadlock in an operating system is a condition when every process waits for a
resource acquired by other processes. It is a series of blocked processes holding a resource and
waiting for accessing extra resources assigned with another one. In the situation of deadlock,
none of the programs can continue until another program releases resources. Therefore, it
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
becomes difficult for the users to continue with their programs. Besides this, it is also annoying
when the system hangs frequently.
This usually occurs in multitasking as well as client-server circumstances. Earlier, systems used
to run only a single program at a time assigning all the resources to that program. Afterwards,
multiples programs were run simultaneously on the operating system. In this case, programs
needed to identify the resources in advance they require to complete their tasks. This method is
used for avoiding conflicts with another task executing simultaneously. Ultimately, some OS
provided an active distribution of resources. Programs ask for further distribution of the
resources after starting their execution and this led to the occurrence of deadlock.
Deadlock can also be defined as a situation two computer program uses same resource of data
and they share access. During the deadlock situation, these computer programs will hinder each
others' way. Most importantly, the access to the shared resource would be denied to both of these
programs during deadlocks. Furthermore, as an ultimate result, the functions of both of these
computer programs stop or collapse. As already said, the problems of the deadlock were
relatively lower in the OS of computers earlier. This is because the previous operating systems
allowed the functioning of only one computer at a time. This minimized any chance of conflict
regarding the access of resources between two or multiple computer programs. Hence deadlocks
in the Operating System were less. However, in the recently programmed OS, with better
interface and processors, multiple programs run at the same time. When that happens, the
probability and instances of the programs overstepping the other while accessing the resources
also increase. The existence of deadlocks affects the performance of the programs. In addition to
this, it also negatively influences the output and slows down the process.
Document Page
To curtail this situation, provisions were made. The operators of the programs were required to
give prior notifications and specifications about the resources that they operate on. This would
minimize the conflicts of the co-existing programs. However, in recent times, operating systems
have come up with the allocation of resources that are dynamic. In this system, programs that
started running with a specific resource can request other resources while the program is running.
This again takes the problem of deadlocks to square one.
The system has the definite number of resources to be distributed among the processes. It is
evident that the computer processes need various types of resources to complete execution of
activities. However, these resources are approved in systematic order. These include- requesting,
waiting and realizing:
Requesting: Resources are asked for by the processes.
Waiting: The operating system grants accessible resources. In the case of unavailability
of resources as well as demanding resources, the process is required to wait.
Realizing: The process utilizes the accessible resources and releases it on completion of
the tasks.
If there is no resource available, none of the programs can execute since the release of
resources they need. The request resources are associated with other programs that are also
waiting for resources held by some other programs. Now, we shall move forward to the causes of
deadlocks.
Causes of deadlocks in the operating system
A deadlock in operating system arises when the following four conditions hold at the same time
in the system:
Document Page
Mutual Exclusion
At least one or more than one of the allocated resources are not shareable. Each resource is
assigned with only one process at a time. If any other process demands the same resources. The
demanding process is required to wait until the executing process releases it. The process of
mutual exclusion or rather the condition of mutual exclusion is said to exist in case of deadlock.
This happens when there is a single resource that can possibly be allocated to one program and
not more than that.
Hold and Wait
Requesting process already holds a resource and waits for other resources that are currently
being used by the other process. Hold and wait is another condition that can lead to a deadlock
situation in an Operating System. According to this condition, it is provided that a single
program can use multiple resources for its functioning. Even after that, it requests resources from
other programs. A hypothetical example can be considered. Process P is using Resource 5 and
resource 6. Process Q is using resource 2. Even then Process P requests from Resource 2 from
Process Q.
Non-Pre-emption
Resources that are assigned to the other tasks cannot be prompted. Once if a resource is held by a
process, it can be not taken away from the active process. The requesting process has to wait
until the process of holding this resource releases it willingly. This condition provides that a
resource can in no way be preempted from a process. A process and resource will only be
detached if the program by a voluntary measure let go the resources. Hence a process cannot pre-
empt a resource from another process before it is done with the execution. On trying to do so,
deadlock arises.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
Circular wait
A circular wait causing a deadlock is a kind of a circular loop. This is generally caused due to an
interconnected circular chain of processes and resources. Besides this, a series of processes that
are waiting for each other in a chain system must exist. Here, each process in the chain waits for
that resource detained by another process in the circular chain. This occurs when the first process
is waiting to hold the resource that is held by the second process. On the other hand, the second
process also waits to hold the resource that is held by the third process. This continues depending
on the number of process and its resources. The endpoint of this circular loop lies where the last
process waits to hold the resource held by first process. Sounds a bit confusing, but in practical
scenario, deadlocks can hamper or cause delay in the activities.
When we are aware of the causes of deadlocks, now we can discuss on the methods to handle
such situations.
Methods for Handling Deadlocks
Since the description and the conditions leading to a situation of deadlocks has been described.
Now, we will shed light on what are the different ways of handling deadlocks in an OS. One can
handle the deadlock issues as well as situations. There are mainly three ways to deal up with the
deadlocks in the operating system and they are:
ï‚· Deadlock prevention or avoidance
ï‚· Deadlock detection and recovery
ï‚· Ignore the problem altogether
Deadlock Prevention or Avoidance:
The deadlock prevention method is the easiest method for handling deadlocks. In this method,
deadlocks can be prevented by avoiding any one of the mentioned four conditions necessary for
Document Page
the deadlocks. Most importantly, as these four conditions are mandatory, the system can prevent
deadlocks eliminating one of them.
Effective measures must be taken so that no transaction between the processes and resources
takes place leading to a deadlock. Besides this, the system evaluates every transaction
beforehand. If any possibility of a deadlock is seen, the transaction is seized from the action. For
the prevention of deadlocks, time schemes like wait-die schemes and wound-wait schemes are
used. The underlying idea behind the occurrence of deadlocks is that all the instances of the
Coffman Condition function at once. Deadlocks can be prevented by the simple concept of
failing even either of these conditions. No matter how easy or simple this may sound, the
implementation of this method physically is still debatable. But then again, operators use such
interface to deal with the situations of deadlocks.
In deadlock avoidance, it is checked by the OS whether the system is in a safe stage or unsafe
stage. Most importantly, the avoiding process works until the system comes to safe states.
Besides this, the operating system determines distribution of resources ensuring that the
resources and not creating deadlocks. This approach includes the elimination of the condition of
mutual exclusion, no prompt, hold and wait and circular wait. We can prompt a resource from
one process and provides it to another requesting process. This will not allow the system to go
into a deadlock state.
Detection and Recovery from Deadlocks
If deadlock prevention or avoidance approach fails, detection and recovery from deadlocks is
another way to deal with deadlocks. Moreover, the deadlock detection is a process used to
determine whether the deadlock exists or not. This approach identifies the resources as well as
the process causing the deadlocks. The basic thing is to test the distribution of resources. Once
Document Page
the deadlock is detected, you are required to break it. It can be done using various methods such
as eliminating one or more processes waiting in a circular chain. In addition to this, taking away
the resources from other processes which are also deadlocks is used for recovery.
In this mechanism, OS neither neglect the occurrence of deadlocks nor utilize any method to
avoid or prevent the deadlocks. For overcoming the situations of deadlocks, the OS every so
often checks the systems on regular basis. If there is any deadlock available, recovery techniques
are used by the operating system for recovering the system. The recovery method includes the
ending of the process in deadlocks. After ending all the process it again looks for the deadlocks.
You need to repeat this process until the system becomes deadlocks free.
A deadlock can be easily detected by employing a resource scheduler. The work of a resource
scheduler is to track all the resources and processes available in the system. It can track the
different resources that are held by different processes. Once the tracking is done and the
deadlock is detected what can be done is that all the processes employed should be terminated
even though that means the loss of complete progress. After that, a few resources can be
extracted and allocated to other processes before the deadlock situation is completely resolved.
Ignorance of Deadlocks Altogether
Ignorance of deadlock is an effective way of handling deadlocks by avoiding the situation to
arise. Wait for graph technique can be used where the existence of an edge in graph shows the
presence of deadlock. The method of avoidance of deadlock is mainly analyzing the activities in
the operating system. At every step process is followed to evaluate whether the process is safe or
not. Once an unsafe activity is detected, the OS takes a step back to prevent the deadlock
This is one of the most widely used mechanisms to deal with the deadlocks.
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
This method is used by most of the operating systems, especially for end users operations. In
this method, OS assumes that there is no occurrence of deadlocks. It just ignores it, the users
have to just restart the system in the situation of deadlocks. This approach is used when the
interval time among the occurrences of deadlocks is less. The data lost by the occurrences of
deadlock are bearable. Thus, this approach believes that deadlock occurs rarely.
Ostrich Algorithm
This might seem like a fancy terminology for most of you. It has a complex system or process
associated with it. In reality, it is probably one of the simplest and easiest ways of handling a
deadlock. The Ostrich Algorithm simply means avoiding the deadlock that had arisen. This is
done because the elementary cost incurred to handle the deadlock is relatively much higher.
Moreover, this is effective for systems where the deadlocks arise rarely. So it is assumed that the
deadlock situation will not arise again and simply the system is rebooted.
This system is most importantly used for the end users. It is most relevant in the end users
approach. This method also talks about the importance of the end user being a single user.
However, this method of handling with deadlocks is not very robust or not applicable in
dynamic sets of activities. It can be effective when the user takes up normal and basic activities
like simple browsing.
The bridge between standard performance and actual performance is ever existent. Therefore,
persistent use of deadlock handling mechanisms reduces the performance of the system. If the
occurrence of deadlocks is extremely meager, the use of these mechanisms is unnecessary.
However, only restarting the system would serve the purpose. Linux and Microsoft Operating
System follow this approach.
Document Page
Using technology and computers has become a part of our daily. But most importantly, we look
at it from a surface level. This blog on might just answer the questions that may arise in your
mind every time your system hangs.
chevron_up_icon
1 out of 9
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]