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

Term Paper OS

Uploaded by

parasrpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Term Paper OS

Uploaded by

parasrpal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Lovely Professional University, Phagwara, Punjab

CS316: Operating Systems


Term Paper: Deadlock

Submitted By: Sparsh Yadav, Ayush Kumar, Paras Pal


Registration Numbers: 12216519,12216635, 12223269
Roll Numbers: 11, 12, 35
Section: KE147
Submitted to: Mr. Anurag Singh (29400)

Marks Obtained
Maximum Marks
Remarks
Deadlock:
Sparsh Yadav ([email protected]) | Ayush Kumar
([email protected]) | Paras Pal ([email protected])

Abstract
Defining Deadlock:
In the world of operating systems,
deadlocks are a serious problem that In essence, a deadlock occurs when
seriously compromise the stability and numerous processes wait for resources that
dependability of the system. The purpose of are currently used by some another
this abstract is to give a general overview of processes, which prevents them from
deadlocks by examining their origins, moving forward. Imagine an impasse as a
methods of detection, and preventative confrontation between two people, each
measures. When more than 2 processes are holding a key that the other needs to move
stopped waiting for a single resource that it forward with. Both are unable to move
is holding, it is referred as deadlock. A further without giving up their respective
deadlock may only occur in the cases keys, creating a deadlock. This type of
comprising: no pre-emption, hold and wait, deadlock occurs in computer systems when
mutual exclusion, and circular wait. processes come to a standstill and are
Numerous methods, such as resource pre- unable to release resources they are holding
emption and cautious resource allocation while waiting on resources held by others.
policies, have been devised to detect and
prevent deadlocks. Examples of deadlock
detection algorithms include the Banker's
algorithm. This abstract emphasizes how
crucial it is to comprehend deadlocks and
take preventative action to lessen their
negative effects on the system.

Introduction
Within the fields of operating systems and
computer science, deadlocks are a
confusing situation in which the smooth
flow of operations comes to an abrupt stop.
This is a dilemma in which one or more Understanding Deadlock Conditions:
processes are in a state of non-
determination and are withholding
resources that are essential to the progress
of the other. Deadlocks pose serious risks to In order to fully comprehend deadlocks, it
system performance, resource usage, and is imperative to comprehend the underlying
stability, making them a major challenge in causes of them:
system design and management.
resource while waiting for another, there
1. Mutual Exclusion: may be a resource deadlock.

At any given moment, only a single process


can access resources such as files, database
records, or input/output devices. Future
conflicts and resource competition are
made possible by this exclusivity.

4. Circular Wait:
A sequence of processes that are in a circle,
each waiting for a resource that is being
2. Hold and Wait: consumed by the process after it. A similar
scenario of deadlock results from this cyclic
Procedures can be used to hold resources
dependency, in which no other process may
until further resources are needed. This
move forward without acquiring a resource
condition may lead to resource hoarding, a
that is being held by another.
situation in which processes cling to the
resources they already have and impede the
progress of others.

The Ramifications of Deadlocks:

Deadlocks affect system operations in a


variety of ways.

• System Paralysis: Deadlocks cause the


3. No Pre-emption: system as a whole to come to a complete
stop, stopping the execution of impacted
There is no way to make processes give up programs and sometimes interfering with
resources. Therefore, if a process cannot be vital system functions.
terminated or pre-empted while holding a
Processes that abide by the hold and wait
• Resource Wastage: When resources held condition may become stuck if other
by stalled processes are left idle, they are processes are holding the necessary
not used efficiently and become unavailable resources while they hold them and wait for
to other processes. more. For example, mutual exclusion
causes a deadlock if Process X1EA has
Resource H1SO and is waiting for
• Reduced Throughput: When processes Resource MN3O, while Process SO3E has
are unable to advance, the system's Resource MN3O and is waiting for
throughput is reduced, which impacts Resource H1SO.
responsiveness and performance as a
whole. Implications in Resource Allocation:

Mutual exclusion affects how computer


• Risk of Famine: Unfair resource systems allocate and use resources in real-
allocation and famine may result from world applications. It guarantees data
processes outside of the impasse being integrity and avoids conflicts between
denied resources forever. concurrent access, but if not handled
appropriately, it can also result in resource
Effective deadlock management and contention and inefficiency. Resources that
prevention techniques are essential to are mutually exclusive may need lengthy
preserving system efficiency and stability wait times for processes to access them,
in face of these effects. System designers which could result in system throughput
can create strong procedures to reduce the reduction and performance bottlenecks.
dangers associated with deadlocks and
guarantee the smooth operation of Hold and Wait Condition:
computer systems by having a thorough
understanding of the complexities of Hold and wait describes a scenario in which
deadlock generation and its ramifications. a process maintains resources it has
previously obtained while holding out for
Mutual exclusion new resources to become available. Put
differently, a process can wait for additional
The idea of mutual exclusion states that resources that are currently being held by
only one process at a time can access other processes while simultaneously
particular resources or crucial portions of holding onto the resources it now has and
code. This exclusivity makes sure that when preventing other processes from obtaining
several processes try to access common them. If processes become stuck while
resources at the same time, conflicts and waiting for resources, this condition creates
inconsistent data are avoided. Common the possibility of resource contention and
synchronization techniques used in deadlock.
operating systems and concurrent programs
to guarantee mutual exclusion are locks, Significance in Deadlock Formation:
semaphores, and mutexes.
Deadlock situations are based on the hold
Significance in Deadlock Formation: and wait condition, mutual exclusion, no
pre-emption, and circular wait. Deadlock
Mutual exclusion creates situations where can happen when processes hold resources
processes can hold resources forever while while waiting for more to become available
they wait for others to release them, which if the necessary resources are held in a
lays the stage for possible deadlocks. circular dependency by other processes. A
deadlock results from hold and wait, for affected by no pre-emption. Although it
instance, if Process X1EA holds Resource guarantees that processes cannot be stopped
H1SO and is waiting for Resource MN3O, arbitrarily or have their resources taken
while Process SO3E holds Resource MN3O away, it also raises the possibility of
and is waiting for Resource H1SO. inefficiency and resource hoarding. It is
possible for processes to hang onto
Implications in Resource Allocation: resources indefinitely, which could result in
resource contention and deadlock by
The effectiveness of computer systems' blocking other processes from accessing
resource usage is greatly impacted by hold them.
and wait. It creates the possibility of Circular wait
resource hoarding and inefficiency even
while it enables processes to obtain Circular Wait Condition:
resources progressively as needed. It is
possible for processes to cling onto The term "circular wait condition" refers to
resources they now have while they wait for a situation in which a sequence of processes
others, which could result in resource is circular and each process in the chain is
contention and a reduction in system waiting for a resource held by the process
throughput. behind it. Stated differently, the circular
dependency looks like this: Up till Process
No Pre-emption Condition: N is waiting for a resource that Process A
has, Process A is waiting for a resource that
According to the no pre-emption condition, Process B has, Process B is waiting for a
resources owned by a process cannot be resource that Process C has, and so on. This
taken away from it by force; instead, they circular dependency causes deadlock
must be released voluntarily. Put because it prevents one process from
differently, a process retains a resource it moving forward without accessing a
has acquired until it releases it willingly resource that another is holding.
after completing its task. If a process that is
holding a resource is waiting on another Significance in Deadlock Formation:
resource that is held by a different process,
this condition could lead to a circular The circular wait condition, mutual
dependency and deadlock. exclusion, hold and wait, and lack of pre-
emption are the foundations of deadlock
Significance in Deadlock Formation: scenarios. Processes in a circular
dependency that have at least one resource
The no pre-emption condition, mutual while waiting on another resource held by a
exclusion, hold and wait, and circular wait separate process farther down the chain
are the foundations of deadlock scenarios. may experience deadlock. This circular
When resources are held by other processes dependency causes deadlock, which
and cannot be pre-empted, processes may prevents any further processing.
experience deadlock as they wait for more
to become available. If no process provides Implications in Resource Allocation:
its resources willingly, the deadlock never
ends. Computer system fairness and resource
distribution are significantly impacted by
Implications in Resource Allocation: circular wait. It presents the risk of resource
hoarding and inefficiency even as it permits
The equitable distribution of resources and gradual resource acquisition and flexibility
fairness in computer systems are greatly in resource management. While waiting for
additional resources, processes may cling without upsetting the system as a whole.
onto the ones they already have, which
could result in resource contention and
deadlock. 6. Data Corruption and Inconsistency: If
deadlock resolution entails reversing
Deadlocks can lead to several significant transactions or forcibly ending processes,
issues in a computer system: the system may be left in an inconsistent
state when deadlocks occur in transactions
1. System Halting: Deadlocks have the requiring crucial data operations (such as
ability to bring down the system as a whole. database transactions). Data integrity
Deadlocked processes are unable to move problems and corruption may result from it
further, which results in their execution Generally, deadlocks constitute a serious
coming to an absolute stop. This can have risk to computer systems' performance,
an impact on users or other processes that stability, and dependability. As a result,
depend on those resources. sustaining system availability and
functionality requires efficient deadlock
2. Waste of Resources: When prevention, detection, and recovery
processes are unable to release techniques.
resources, they are frequently held
indefinitely as a result of deadlocks. In In many real-world situations, deadlocks
addition to preventing other processes— can happen, particularly in systems with
even those not implicated in the shared resources and concurrent activities.
deadlock—from accessing those Here are a few real-world situations where
deadlocks could occur:
resources, this results in inefficient
resource consumption.
1. Database Management Systems
(DBMS):
3. Decreased Throughput: The system's
throughput drops as a result of the • Access to database tables, rows, or records
processes engaged in the deadlock is contested by many transactions. A
stopping. This may have an effect on the deadlock can happen when one transaction
system's overall performance and lead locks down a resource and waits for another
to task execution delays. transaction to lock down the resource.

4. Starvation: Because the stalled 2. Operating System Resource


processes are continuously acquiring Allocation:
resources, there are situations in which
processes outside the deadlock may not be • In systems with several threads or
able to use them. When certain processes processes, access to common resources like
are unable to advance forever, it might memory, files, or input/output devices may
result in hunger. be contested by threads or processes. A
stalemate may occur if all processes share
5. Complexity in Debugging and resources and wait for one another.
Troubleshooting: In complex systems with
numerous interacting processes and 3. File Organization:
resources, deadlocks can be difficult to
identify and fix. It can take a lot of time and
effort to determine the underlying reason of • File systems frequently allow several
a stalemate and to execute a solution processes to access files at once. A
deadlock might happen when two processes
are unable to go forward simultaneously Implementing techniques to make sure that
because one is waiting for another process a system cannot experience the
to lock a file. prerequisites for deadlock entails deadlock
prevention.

4. Networking Protocols: The following are some methods that are


frequently employed to avoid deadlocks:
• When several nodes or devices fight for
access to common resources like network
bandwidth or communication channels, 1. Avoiding mutual exclusion:
networking protocols may experience
deadlocks. In a distributed system, for
instance, a deadlock may occur if two nodes • Make sure that sharing resources among
each possess resources and wait for the several processes doesn't result in
other to retain resources. misunderstandings or discrepancies. The
mutual exclusion condition can be avoided
by making some resources, such read-only
5 . Allocating Resources in Distributed files or read-only database records,
Systems available to several processes at once.

• In distributed systems, there could be 2. Hold and Wait Avoidance:


competition between several nodes to get
distributed resources like distributed file • Make sure that all required resources are
systems, distributed locks, or distributed requested and acquired before processes
databases. start to execute. A process releases the
resources it is now holding and tries again
Software Applications and Concurrency later if it is unable to collect all necessary
Control: resources. The hold and wait condition can
be prevented by making sure that processes
Deadlocks can happen in software don't hold resources while they wait for
applications that have concurrent other processes.
execution, such as multi-threaded programs
or client-server systems, if several threads
or processes fight for access to shared 3. No Preemption:
resources like semaphores, mutexes, or
crucial sections. • Permit preemptive resource distribution,
in which processes may be forced to
relinquish resources as necessary. A
Deadlocks can occur in any of these process that is holding resources may be
situations when several entities or processes preempted and its present resources
interact and vie for access to resources that released to be used by other processes if it
they are holding jointly. In situations like seeks additional resources that are not
this, identifying and resolving deadlocks available. This stops procedures from
necessitates careful system design, the hoarding resources while they wait for
application of suitable synchronization other resources.
techniques, and efficient deadlock
avoidance and detection methods. 4. Avoiding Circular Waits:

Deadlock Prevention Techniques: To avoid circular wait scenarios, impose a


stringent ordering on resource demands.
Assign a unique numerical identifier to
every resource, for instance, and mandate
that processes submit resource requests in
ascending order. Circular waits are avoided
by making sure that processes cannot wait
for resources held by processes with lower
IDs.

4. Resource Allocation Rules:

• Put in place rules for resource allocation


that automatically avoid stalemate. One
such rule is the Banker's method, which Operating systems use Baker's algorithm, a
guarantees secure resource allocation—that deadlock prevention technique, to allocate
is, deadlock would not happen even if all resources. It is mostly used in systems that
processes' resource requests were approved have several processes that need to have
at the same time. exclusive access to certain resources. This
is how it typically operates:
5. Resource Hierarchies:
Number Assigning: A distinct number is
• Introduce hierarchies of resources, in given to every process.
which resources are arranged into tiers and
requests for resources are limited to those at Request Phase: Processes may request
the level of the process in question or lower. resources in any sequence during the
request phase. A process sets its number to
A strong system design must include
the maximum of all the other processes'
deadlock detection and recovery
procedures, which act as a safety net in the numbers plus one and sets its flag to signify
case that deadlock prevention techniques that it wishes to enter the crucial section.
are ineffective.
Check Phase: The procedure determines
The following is a thorough explanation of whether another procedure has asked to
deadlock recovery and detection: access the crucial area. It waits until the
other process hits the crucial region or its
request is fulfilled if it discovers any
Identifying Deadlocks:
processes with a lower number or a similar
number but a lower priority.

Banker’s Algorithm: Exit Phrase: The procedure resets its flag


to signify that it is no longer interested after
finishing the crucial portion.
Because each process is assigned a priority
based on its assigned number, the method
makes sure that they enter the crucial area
in the order that they are assigned,
eliminating deadlock.

Although Baker's approach avoids


deadlock, it might not be the best option in Systems have the ability to identify possible
terms of performance, particularly in deadlocks through timeouts and alarms. A
systems where a lot of processes are vying process may be in a deadlock if it is waiting
for resources. As a result, it's frequently for a resource for an abnormally lengthy
used with other methods for avoiding period of time.
deadlocks and managing resources.
Deadlock Recovery:

1. Termination:
Resource Allocation Graph (RAG):
Finding and ending one or more of the
processes causing the deadlock is one
method of deadlock recovery. The system
can return to normal operation and other
processes can continue executing by
releasing the resources that these processes
were holding. To make sure that ending
processes doesn't result in data loss or
corruption, caution must be used.

Resource allocation graph generation and


2. Resource Preemption:
analysis is a popular technique for detecting
deadlocks. Resources are represented as Preempting resources from one or more of
edges in this graph, and processes are the processes causing the stalemate is an
represented as nodes. Deadlock situations additional strategy. Other processes can
can be identified by looking for cycles in obtain the resources they need to continue
the graph. If a pattern is discovered, it operating by forcibly removing resources
suggests that possible deadlocks may exist. from these processes. Implementing
preemption can be difficult since it
1. Wait-for Graph:
sometimes calls for rolling back
A wait-for graph records resource requests transactions or making sure that processes
as well as resource allocation, much like the that have been preempted can safely
resource allocation graph. Every process is recover from resource loss.
shown as a node, and the edges show which
processes are waiting for resources that
3. Transaction Rollback:
other processes have. Potential deadlocks
are indicated by cycles in this graph. Resolving a stalemate in a system that uses
transactions may require rolling back one or
more of the stalled transactions. The
2. Resource Allocation Table:
impasse can be broken and resources
Some systems keep an inventory of the released by reversing the consequences of
resources that are being held by particular these transactions. Transaction rollbacks
processes at any one time, as well as the should be done cautiously though, as they
resources that each process is awaiting. may affect the consistency and integrity of
Potential deadlock scenarios, like cyclic the data.
waits, can be found by examining this table.
4. Releasing and Reacquiring Resources:
3. Timeouts and Alarms:
In certain situations, breaking a deadlock discussions, and the online technical
may entail freeing up all the resources that communities for their helpful resources and
the stalled processes are holding and examples. Their contributions have made
enabling them to reacquire resources in a my journey of understanding operating
different order. To guarantee the secure systems more enriching. I've gained a
acquisition and release of resources, this deeper appreciation for computer
strategy can call for process coordination.
programming as an art and science, thanks
In general, in the presence of deadlock to their dedication to advancing knowledge
scenarios, deadlock detection and recovery in this field.
techniques are critical to preserving system
availability and stability. System
administrators can lessen the negative References
effects of deadlocks on system performance
and guarantee the smooth running of their For the purpose of gathering information
systems by proactively detecting deadlocks for a project on "Deadlock" in operating
and putting appropriate recovery systems, I have compiled a list of
procedures in place. references. Academic lecture notes,
technical discussion boards, learning
Conclusion websites, and professional networking sites
are some examples of these resources. They
Operating system deadlocks can be quite have been essential in creating a thorough
harmful since they can render some grasp of operating system thread scheduling
programs or even whole systems and synchronization, covering a wide range
inoperable. To sum up, in order to reduce of topics from theoretical ideas to real-
the frequency and severity of deadlocks, world applications.
operating systems must provide efficient
deadlock detection, prevention, and 1.GeeksforGeeks. (n.d.). Deadlock in
recovery procedures. These mechanisms Operating Systems. Retrieved from
include deadlock detection algorithms like https://www.geeksforgeeks.org/.
Banker's algorithm and resource allocation
techniques like resource preemption. 2.Parvati, P. (n.d.). Deadlock in C.
Furthermore, careful programming Retrieved from https://www.linkedin.com/.
techniques, transparent resource allocation
guidelines, and appropriate system design 3.Brazilian Journal of Science. (n.d.).
can all help reduce the likelihood of Basics of deadlock. Retrieved from
deadlocks. All things considered, deadlocks https://www.brazilianjournalofscience.org/.
are a complicated problem in operating
4.Stack Overflow. (n.d.). Advance
systems, but preemptive steps can greatly
Deadlock and theory Retrieved from
lower their frequency and guarantee the
stability and dependability of the system. https://stackoverflow.com/.
5.TutorialsPoint. (n.d.). Operating System –
Acknowledgements Processes and Deadlock Retrieved from
https://www.tutorialspoint.com/.
We want to express my sincere thanks to the
educators, researchers, and developers who 6.Programiz. (n.d.). Learn Deadlock
have helped me understand the complex Programming. Retrieved from
topic of Deadlock in operating systems. I'm https://www.programiz.com/.
particularly grateful to my professors for
their guidance, my peers for the interesting
7.Oracle. (n.d.). Java SE Documentation -
Deadlock Retrieved from
https://docs.oracle.com/.
8.Microsoft Docs. (n.d.). Deadlock (C#).
Retrieved from
https://docs.microsoft.com/.
9.IBM Knowledge Center. (n.d.). Deadlock
Retrieved from
https://www.ibm.com/support/knowledgec
enter/.
10.TechTarget. (n.d.). What is deadlock
Safety and Why is it Important? Retrieved
from
https://searchapparchitecture.techtarget.co
m/.
11.The Crazy Programmer. (n.d.).
Operating System Deadlock. Retrieved
from
https://www.thecrazyprogrammer.com/.

You might also like