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

Os Unit III Notes

The document discusses deadlocks in operating systems, defining them as situations where processes are unable to proceed due to circular waiting for resources. It outlines methods for handling deadlocks, including detection, prevention, and avoidance techniques, such as the banker's algorithm and resource allocation graphs. The importance of preventing deadlocks is emphasized, as they can lead to significant performance degradation and data loss.

Uploaded by

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

Os Unit III Notes

The document discusses deadlocks in operating systems, defining them as situations where processes are unable to proceed due to circular waiting for resources. It outlines methods for handling deadlocks, including detection, prevention, and avoidance techniques, such as the banker's algorithm and resource allocation graphs. The importance of preventing deadlocks is emphasized, as they can lead to significant performance degradation and data loss.

Uploaded by

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

OPERATING SYSTEMS

UNIT III
Deadlocks: System model, Deadlock characterization, Methods for
handling deadlocks, Deadlock
prevention, Detection and avoidance, Recovery from deadlock.

Deadlock System Model


In a computer system a deadlock is where two or more processes are unable to proceed
because each process is waiting for the other to release a resource that it needs to continue
execution. In other words, a deadlock occurs when two or more processes are in a circular
wait state, and none of them can release the resources they hold until they receive the
resources they are waiting for.

Deadlock System Model − The Deadlock System model is a way to describe and
analyze systems that may be prone to deadlocks, which occur when two or more processes
are unable to proceed because they are each waiting for the other to release a resource.
Below are the components of this model −
 Resources − The system has a set of resources that are shared among
processes. These resources can be hardware or software components, such
as memory, files, printers, or network connections. Each resource is identified
by a unique name or identifier.
 Processes − The system has a set of processes that request and release
resources. Processes are units of execution that can be started, suspended,
resumed, and terminated. Each process is identified by a unique process ID.
 Resource Allocation − Each resource can be in one of two states , allocated
or available. A resource that is allocated to a process cannot be used by any
other process until it is released.
 Request and Release − A process can request a resource by sending
a request to the system. If the resource is available, it will be allocated to the
process. When a process is finished using a resource, it must release it so
that it can be used by other processes.
 Resource Dependency − Some processes may require multiple resources to
complete their tasks. A resource dependency graph can be used to
represent the relationships between processes and resources and to detect
potential deadlocks.
 Deadlock Detection − A deadlock can occur when two or more processes
are waiting for resources that are being held by other processes, creating a
circular dependency. Deadlock detection algorithms can be used to detect
when a deadlock has occurred, so that corrective action can be taken.
 Deadlock Resolution − Once a deadlock has been detected, it can be
resolved by breaking the circular dependency between the processes. This
can be done by releasing one or more resources that are being held by a
process, or by preempting one or more processes that are holding resources.
The Working of some of the techniques are given below −
o Resource preemption is a technique used to break the circular
wait condition of a deadlock. The operating system can preempt
resources from one or more processes involved in the deadlock
and allocate them to the processes that need them. Preemption
can be done either selectively or globally. In selective
preemption, only the resources that are required to resolve the
deadlock are preempted, while in global preemption, all the
resources held by the deadlocked processes are preempted.
o When a process is terminated, all the resources held by
the process are released, and other processes can proceed.
However, this approach can lead to data loss and inconsistency
if the terminated process was in the middle of a critical task.
 Deadlock Avoidance − Deadlock avoidance is a technique used to prevent
the occurrence of deadlocks in a computer system. The goal of deadlock
avoidance is to ensure that all resources required by a process are available
before the process starts execution, thereby avoiding the possibility of
deadlock.

There are several algorithms that can be used for deadlock avoidance, including the
banker's algorithm and the resource allocation graph. These algorithms use a mathematical
model to analyze resource allocation and to determine whether a process should be allowed
to start or wait for resources.

 The banker's algorithm is a widely used method for deadlock avoidance. It is


a resource allocation algorithm that checks whether a requested resource can
be granted to a process without causing a deadlock. The algorithm works by
simulating the allocation of resources and checking whether a safe state can
be reached. A safe state is a state where all processes can complete their
execution without causing a deadlock.
 The resource allocation graph is another method for deadlock avoidance. It
represents the allocation of resources as a directed graph. Each process is
represented by a node, and each resource is represented by an edge. The
algorithm checks for cycles in the graph to determine whether a deadlock has
occurred. If a cycle is detected, the process requesting the resource is
blocked until the required resource becomes available.
Conclusion
In summary, the deadlock system model is a crucial idea in the design and management
of operating systems. It outlines the potential causes of deadlocks as well as strategies for
avoiding and resolving them. It is crucial to put into practice efficient prevention measures
for deadlocks since they might result in substantial performance degradation and data loss.
Deadlock characterization
A deadlock happens in operating system when two or more processes need some resource
to complete their execution that is held by the other process.

A deadlock occurs if the four Coffman conditions hold true. But these conditions are not
mutually exclusive. They are given as follows −

Mutual Exclusion
There should be a resource that can only be held by one process at a time. In the diagram
below, there is a single instance of Resource 1 and it is held by Process 1 only.

Hold and Wait


A process can hold multiple resources and still request more resources from other
processes which are holding them. In the diagram given below, Process 2 holds Resource 2
and Resource 3 and is requesting the Resource 1 which is held by Process 1.

No Preemption
A resource cannot be preempted from a process by force. A process can only release a
resource voluntarily. In the diagram below, Process 2 cannot preempt Resource 1 from
Process 1. It will only be released when Process 1 relinquishes it voluntarily after its
execution is complete.

Circular Wait
A process is waiting for the resource held by the second process, which is waiting for the
resource held by the third process and so on, till the last process is waiting for a resource
held by the first process. This forms a circular chain. For example: Process 1 is allocated
Resource2 and it is requesting Resource 1. Similarly, Process 2 is allocated Resource 1
and it is requesting Resource 2. This forms a circular wait loop.
Methods for Handling Deadlocks
Deadlock detection, deadlock prevention and deadlock avoidance are the main methods for
handling deadlocks. Details about these are given as follows −

Deadlock Detection
Deadlock can be detected by the resource scheduler as it keeps track of all the resources
that are allocated to different processes. After a deadlock is detected, it can be handed
using the given methods −

 All the processes that are involved in the deadlock are terminated. This
approach is not that useful as all the progress made by the processes is
destroyed.
 Resources can be preempted from some processes and given to others until
the deadlock situation is resolved.
Deadlock Prevention
It is 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 possibility that a transaction may lead to deadlock, it is never allowed to execute.

Some deadlock prevention schemes that use timestamps in order to make sure that a
deadlock does not occur are given as follows −

 Wait - Die Scheme


 In the wait - die scheme, if a transaction T1 requests for a resource that is
held by transaction T2, one of the following two scenarios may occur −
o TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in the
system earlier than T2, then it is allowed to wait for the resource
which will be free when T2 has completed its execution.
o TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came in the
system after T2, then T1 is killed. It is restarted later with the
same timestamp.
 Wound - Wait Scheme
 In the wound - wait scheme, if a transaction T1 requests for a resource that is
held by transaction T2, one of the following two possibilities may occur −
o TS(T1) < TS(T2) - If T1 is older than T2 i.e T1 came in the
system earlier than T2, then it is allowed to roll back T2 or
wound T2. Then T1 takes the resource and completes its
execution. T2 is later restarted with the same timestamp.
o TS(T1) > TS(T2) - If T1 is younger than T2 i.e T1 came in the
system after T2, then it is allowed to wait for the resource which
will be free when T2 has completed its execution.
Deadlock Avoidance
It is better to avoid a deadlock rather than take measures after the deadlock has occurred.
The wait for graph can be used for deadlock avoidance. This is however only useful for
smaller databases as it can get quite complex in larger databases.

Wait for graph

The wait for graph shows the relationship between the resources and transactions. If a
transaction requests a resource or if it already holds a resource, it is visible as an edge on
the wait for graph. If the wait for graph contains a cycle, then there may be a deadlock in the
system, otherwise not.

Ostrich Algorithm
The ostrich algorithm means that the deadlock is simply ignored and it is assumed that it will
never occur. This is done because in some systems the cost of handling the deadlock is
much higher than simply ignoring it as it occurs very rarely. So, it is simply assumed that the
deadlock will never occur and the system is rebooted if it occurs by any chance.

Deadlock Prevention
ntroduction
Deadlock prevention is a technique used in computer science to avoid situations where
multiple processes or threads are blocked and unable to proceed because they are waiting
for each other to release resources that they need to complete their tasks. Deadlocks can
be detrimental to the performance of a system and can cause significant delays in
completing tasks. To prevent deadlocks, various techniques such as resource allocation
graph, preemptive scheduling, and detection and recovery are used. Each of these
techniques helps in ensuring that resources are used efficiently and prevent situations
where a deadlock may occur, thereby ensuring optimal performance of the system.

Definition of Deadlock Prevention


Deadlock prevention is a technique used in computer science to avoid situations where
multiple processes or threads are blocked and unable to proceed because they are waiting
for each other to release resources that they need to complete their tasks. The main goal of
deadlock prevention is to ensure that resources are used efficiently and that situations
where a deadlock may occur are avoided. By implementing appropriate techniques for
preventing deadlocks, computer systems can improve their efficiency, reduce delays, and
avoid the risk of system failure caused by deadlocks. Deadlock prevention techniques may
include resource allocation graph, preemptive scheduling, detection and recovery, or a
combination of these methods.

Importance of Preventing Deadlocks


Preventing deadlocks is crucial for ensuring the smooth operation and optimal performance
of computer systems. Deadlocks occur when multiple processes or threads are blocked and
unable to proceed because they are waiting for each other to release resources that they
need to complete their tasks. This can result in significant delays in completing tasks,
reduced system performance, and even system failure. Deadlocks can be especially
problematic in real-time systems, where delays can have severe consequences. Therefore,
preventing deadlocks is essential to ensure that computer systems operate efficiently,
effectively, and reliably. By implementing appropriate techniques for preventing deadlocks,
computer systems can improve their performance, reduce delays, and avoid the risk of
system failure caused by deadlocks.

Resource Allocation Graph


Resource allocation graph is a technique used for preventing deadlocks in computer
systems. In this technique, resources are represented as nodes in a directed graph, and the
edges represent the requests for resources. There are two types of edges in the graph -
request edges and assignment edges. A request edge points from a process to a resource
that the process needs, while an assignment edge points from a resource to a process that
has been allocated that resource.

Detection of cycles in the graph Explanation of resource allocation graph


Deadlocks can occur in the resource allocation graph when there is a cycle in the graph. A
cycle in the graph indicates that a process is waiting for a resource that is held by another
process that is also waiting for a resource held by the first process. This situation creates a
deadlock, and no process can proceed further.

Prevention of deadlocks using resource allocation graph


To prevent deadlocks using the resource allocation graph technique, the system must
ensure that no cycles exist in the graph. If a cycle exists, it means that a deadlock may
occur, and the system must take appropriate steps to break the cycle. This can be done by
either releasing a resource or preemptively removing a resource from a process that is
holding it. By breaking the cycle, the system ensures that no deadlock can occur.

In summary, the resource allocation graph is a useful technique for preventing deadlocks in
computer systems. It allows the system to monitor the use of resources and detect potential
deadlocks by analyzing the graph for cycles. By taking appropriate steps to break the cycle,
the system can avoid the occurrence of deadlocks and ensure the smooth operation of the
system.

Preemptive Scheduling
Preemptive scheduling is a technique used for preventing deadlocks in computer systems.
In this technique, the system is designed to preempt a process that is holding a resource for
too long. When a process is preempted, the system forces the process to release the
resource, which can then be allocated to another process that needs it.
Explanation of preemptive scheduling
To identify processes that are holding resources for too long, the system can use various
techniques such as monitoring the waiting time of processes, tracking the use of resources,
and analyzing the behavior of processes. Once the system identifies a process that is
holding a resource for too long, it can preempt that process and force it to release the
resource.

Forced release of resources to prevent deadlocks


Forced release of resources can prevent deadlocks by ensuring that resources are not held
for extended periods. When a resource is released, it can be allocated to another process
that needs it, thereby preventing a situation where multiple processes are blocked and
unable to proceed.

Preemptive scheduling can be an effective technique for preventing deadlocks, but it may
also introduce some overhead and may not be suitable for all systems. Additionally,
preemptive scheduling may impact the performance of the system if too many processes
are preempted, and resources are frequently released and allocated. Therefore, it is
important to use preemptive scheduling judiciously and evaluate its impact on the system's
performance.

Detection and Recovery


Detection and recovery is a technique used for preventing deadlocks in computer systems.
In this technique, the system periodically checks for the presence of deadlocks and takes
appropriate steps to recover from them if they occur.

Explanation of detection and recovery technique


Periodic deadlock checking
Periodic deadlock checking involves monitoring the use of resources and analyzing the
system's behavior to detect potential deadlocks. The system can use various algorithms to
detect deadlocks, such as the banker's algorithm or the wait-for graph algorithm. Once a
deadlock is detected, the system takes appropriate recovery steps to break the deadlock
and resume normal operation.

Recovery steps such as resource release and process termination


Recovery steps may involve releasing resources that are held by processes involved in the
deadlock or terminating processes that are involved in the deadlock. When a resource is
released, it can be allocated to another process that needs it, thereby breaking the
deadlock. Similarly, when a process is terminated, the resources held by the process are
released and can be allocated to other processes.

Detection and recovery is an effective technique for preventing deadlocks in computer


systems, but it may also introduce some overhead and may not be suitable for all systems.
The frequency of deadlock checking, the recovery steps taken, and the impact of the
technique on system performance must be carefully evaluated to ensure that it is used
appropriately. Additionally, the system must be designed to handle recovery from deadlocks
gracefully and without causing system disruption or data loss.

Comparison of Techniques Advantages and disadvantages of each technique


There are several techniques used for preventing deadlocks in computer systems, and each
technique has its advantages and disadvantages. The appropriate use case for each
technique depends on the system's characteristics, performance requirements, and the type
of resources being used.

Resource allocation graph: Advantages


 Simple and easy to understand
 Provides a visual representation of the system's resource usage
 Can be used to detect potential deadlocks
Disadvantages
 May not be suitable for complex systems with a large number of resources
 Requires constant monitoring and analysis to prevent deadlocks
 May introduce overhead and impact system performance
Appropriate use case − Resource allocation graph is suitable for systems with a small
number of resources and processes.

Preemptive scheduling: Advantages


 Can be effective in preventing deadlocks
 Allows the system to preempt processes that are holding resources for too
long
 Can be used in real-time systems
Disadvantages
 May impact system performance if too many processes are preempted
 May not be suitable for all systems
 Appropriate use case − Preemptive scheduling is suitable for real-time
systems where timely execution is critical, and the system can handle the
overhead introduced by preemptive scheduling.
Detection and recovery: Advantages
 Can detect and recover from deadlocks
 Allows the system to recover from deadlocks without disrupting system
operations
 Can be used in a wide range of systems
Disadvantages
 May introduce overhead and impact system performance
 May not be suitable for systems with strict performance requirements
Appropriate use case − Detection and recovery is suitable for systems with a large
number of resources and processes and can be used in a wide range of systems.

Conclusion
In conclusion, preventing deadlocks is crucial for ensuring the smooth operation and optimal
performance of computer systems. The techniques used for preventing deadlocks, such as
resource allocation graph, preemptive scheduling, and detection and recovery, help in
identifying and avoiding potential deadlocks. By adopting appropriate deadlock prevention
techniques, computer systems can improve their efficiency, reduce delays, and avoid the
risk of system failure caused by deadlocks. The prevention of deadlocks is an ongoing
challenge for computer scientists, and as technology evolves, new techniques and
approaches may need to be developed to keep pace with changing demands and
requirements of modern computing systems.

You might also like