Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

CpE 116 OPERATING SYSTEMS CHAPTER II

CHAPTER II – PROCESS MANAGEMENT / PROCESS COORDINATION

DEADLOCKS

OVERVIEW

In this chapter, we will further dive into the operating system discussing the critical concept of deadlocks. This
chapter will provide a comprehensive overview of deadlocks, its causes and prevention to maintain a
convenient system for the user.

We will begin by defining deadlock and why it is an important concept or concern in operating systems. You
will gain an understanding of how deadlocks arise when multiple processes or threads are carried out in the
operating system leading to deadlocks, making the system unable to make progress.

Throughout this chapter, we will tackle the strategies used to prevent and avoid the occurrence of deadlocks,
providing you the knowledge that you can use in managing efficiently your computer systems and a solid
foundation to build upon as you progress through the modules. Key terms, definitions and real life examples
will be presented to enhance your understanding and facilitate comprehension of the subject matter.

LEARNING OUTCOMES

At the end of this module, you should be able to:

 To acquire comprehensive understanding about deadlocks in the operating system.


 To explore the factors leading to deadlock occurrence in operating systems
 To comprehend strategies for deadlock prevention and importance of deadlock handling

LEARNING CONTENT

Let’s begin by exploring the concepts of deadlock in operating system, by examining various conditions that
lead to deadlock and we will delve into strategies, techniques, and preventive measures to avoid and handle
deadlock in operating systems. This chapter will also cover the approaches for ensuring that the system
remains free from deadlock by determining the available resource for each process, examples will also be
provided to facilitate better comprehension.

Deadlock

In a system there are numerous processes running concurrently, whether in background or triggered by
user input. These processes may compete for a finite number of resources. Each process requires specific
resources to execute its tasks, resources may not always be available and only be released when an input is
being terminated or finished. A deadlock occurs in a situation where a set of processes are blocked because
each process is holding a resource and waiting for another resource acquired by some other process. This
means that many processes are unable to proceed because it is in a waiting state. Processes can request
and use these resources, but they must follow a specific sequence under normal mode of operation:

• Request: The process requests the resource. If the request cannot be granted immediately (for example,
if the resource is being used by another process), then the requesting process must wait until it can
acquire the resource.
• Use. The process can operate on the resource (for example, if the resource is a printer, the process can
print on the printer).
• Release. The process releases the resource.

Necessary Conditions Leading to Deadlock

PANGASINAN STATE UNIVERSITY 1


CpE 116 OPERATING SYSTEMS CHAPTER II

In a deadlock, processes never finish executing, and system resources are tied up, preventing other
jobs from starting. There are four conditions where a deadlock occurs simultaneously in a system:

Condition 1: Mutual exclusion


At least one resource must be held in a non-sharable mode; that is, only one process at a time can
use the resource. If another process requests that resource, the requesting process must be delayed until the
resource has been released. (Illustrative example is shown in Figure 1.1) This illustrates how mutual exclusion
occurs, given that there are two processes P1 and P2, and a resource. The resource R1 is assigned to P1
and P2 is requesting for resource R1 but R1 cannot be shared since it is assigned to a particular process,
therefore P2 needs to wait until P1 will release the resource.

Figure 1.1 Mutual Exclusion

Condition 2: Hold and Wait


A process must be holding at least one resource and waiting to acquire additional resources that are
currently being held by other processes. Looking into the figure 1.2, P1 holds into two resources R1 and R2,
and further requesting for another resources R3. Since R3 is assigned to P2, P1 must wait until it becomes
available while still holding onto two resources R1 and R2.

Figure 1.2 Hold and Wait

Condition 3: No preemption
Resources cannot be preempted; that is, a resource can be released only voluntarily by the process
holding it, after that process has completed its task.

Figure 1.3 No preemption

PANGASINAN STATE UNIVERSITY 2


CpE 116 OPERATING SYSTEMS CHAPTER II

Condition 4: Circular wait


A set {P0, P1, ..., Pn} of waiting processes must exist such that P0 is waiting for a resource held by P1, P1 is
waiting for a resource held by P2, ..., Pn−1 is waiting for a resource held by Pn, and Pn is waiting for a
resource held by P0. The figures 1.4 shows how each processes holding a resources and requesting for
another resource. This leads the processes to be in waiting state.

Figure 1.4 Circular Wait

Resource-Allocation Graph

To precisely describe deadlocks, it can be represented in


terms of a directed graph called a system resource-allocation
graph shown in figure 1.5.

This graph consists of Vertices and Edges.

Graphs consist of:

Vertices (V)
 P = {P1, P2, ... Pn} (the set consisting of all the
processes in the system.)
 R = {R1, R2, ... Rn} (the set consisting of all the
resources in the system. )
Figure 1.5 Resource Allocation Graph
Edges
 Request Edge (Pi  Rj) - process Pi has requested an instance of resource type Rj and is currently
waiting for that resource.
 Assignment Edge (Rj  Pi) - instance of resource type Rj has been allocated to process Pi.
 Claim Edge (Pi  Rj) - indicates that process Pi may request resource Rj at some time in the future.
This edge resembles a request edge in direction but is represented in the graph by a dashed line.

As we look in the graph, each resource ( R1, R2, R3, R4 ) contains instances which represent a single unit or
copy of a particular type of resource. It signifies the availability of that resource type for allocation to
processes. The graph shows how each instances of resources are being distributed or assigned to each
processes, and each processes shows how they request for another resources. Processes P1, P2, and P3
are in deadlocked state. Process P2 is waiting for the resource R3, which is held by process P3. Process P3
is waiting for either process P1 or process P2 to release resource R2. In addition, process P1 is waiting for

PANGASINAN STATE UNIVERSITY 3


CpE 116 OPERATING SYSTEMS CHAPTER II

process P2 to release resource R1. We can now identify if the system is not in a deadlock state by identifying
if the resource allocation graph does not have a cycle, if so, the system is in a deadlock state.

Deadlock Prevention

In an operating system there are a set of rules or procedures implemented to manage the allocation
of resources effectively which is a resource allocation algorithm. This algorithm governs how resources
should be distributed among various processes, ensuring system stability and optimal performance while
preventing potential issues of deadlocks.

There are approaches to handle deadlock that include deadlock prevention. This ensures that at least one of
the necessary conditions for deadlock can never hold.
There are three main ways of preventing deadlocks:

1. Deadlock Prevention/Avoidance - We can use a protocol to prevent or avoid deadlocks, ensuring


that the system will never enter a deadlocked state.
2. Deadlock Detection and Recovery - We can allow the system to enter a deadlocked state, detect it,
and recover.
3. Ignorance - Ignoring the problem altogether and pretend that deadlocks never occur in the system.

To ensure that deadlocks never occur, the system can use either a deadlock prevention or a deadlock-
avoidance scheme. Deadlock prevention provides a set of methods to ensure that at least one of the
necessary conditions that leads to deadlock cannot hold. These methods prevent deadlocks by constraining
how requests for resources can be made. we can prevent the occurrence of a deadlock by examining each
four necessary conditions separately.

Mutual Exclusion: One way to prevent deadlocks is by ensuring that at least one of the four necessary
conditions for a deadlock cannot occur. For example, if we eliminate mutual exclusion (i.e., allow multiple
processes to share a resource simultaneously), deadlocks cannot occur. However, this may not be
feasible for all types of resources.

Hold and Wait: To prevent this condition, a process can request all the necessary resources at once, or it can
release any resources it is holding before requesting additional ones. This approach can be inefficient if
processes often need multiple resources.

No Preemption: If a resource is held by one process and another process requests it, the system may
forcibly take the resource away from the first process. Checking the availability of each process if they
are allocated and if not, we preempt them from a waiting process and allocate to the requester this will
prevent this condition from happening. Preemption only occurs if another process requests the
preempted resources.

Circular Wait: Resources can be assigned a unique numerical value, and processes must request resources
in increasing order. This eliminates the possibility of circular waits and mitigates the risk of deadlock.

Deadlock Avoidance

Besides Deadlock prevention, another approach is to avoid deadlock, which is deadlock avoidance, an
approach to prevent deadlocks by either limiting how requests for resources can be made or by requiring
additional information about how resources are to be requested. This also provides possible effects which
reduce system throughput and lowering device utilization. Let's consider a scenario where User A wants to
book a flight from New York to Los Angeles and then a connecting flight to Honolulu, while User B wants to
book the same connecting flight to Honolulu and then continue to Sydney. In this case the system will analyze

PANGASINAN STATE UNIVERSITY 4


CpE 116 OPERATING SYSTEMS CHAPTER II

the resource requests and identify that both User A and User B need the same seat on the connecting flight to
Honolulu. To avoid a potential deadlock, the system might choose to grant the seat to one user and allocate
an alternative seat to the other, ensuring that both users can proceed with their reservations without causing a
conflict.

As we mentioned earlier, deadlock avoidance requires additional details about resource requests. It relies on
a dedicated algorithm. This algorithm examines the resource allocation state ensuring there is no circular-wait
condition. Through this it will make decisions regarding granting or denying resource requests to maintain
system safety and prevent the occurrence of deadlocks. Resource-allocation state is defined by the number
of available and allocated resources and the maximum demands of the processes. In the following sections,
we explore two deadlock-avoidance algorithms.

With this we can determine whether the system is in safe state or unsafe state. The term suggests a safe
state if a system is not in a deadlock state otherwise it is considered an unsafe state If there exists a safe
sequence of all processes then the system is in safe state. We considered the state of the system safe if,
within that state, the computer system has the capability to allocate resources to each process, respecting
their maximum requirements, in a specific sequence or order.
Figure 1.6 shows deadlock state in spaces. A safe sequence
refers to an ordered list of processes (<P1, P2...Pn>) in a
computer system. It is considered a safe sequence if for each
process Pi, the resources that it can request can be satisfied by
the currently available resources plus the resource which is held
by all previous processes. This means that if Pi cannot
immediately access the required resources, it can wait until all
preceding processes finish their task, and they can obtain the
needed resources to complete its work, release the resources
and terminate. After a Pi terminates, Pi+1 can acquire its
resources and so on. If there's no such safe sequence, we can
say that the system enters a deadlock state.

Figure 1.6

To illustrate further, we will provide examples of how to determine if the processes in the system have enough
resources that are needed for each process to successfully execute its task. And if the system is in its safe
state. The following steps are to determine system state and its safe sequence:

Step 1: Compute Available Resources and Needs: calculate the total available resources by summing all
allocated resources and subtracting them from the given total resources.

Available Resources = Given Resources - Total Allocated Resources

To determine the resources needed of each process, perform subtraction by subtracting the
maximum resources from the allocated resources of each process.

Needs for Process Pi = Maximum Needed Resources - Allocated Resources for Process Pi

Step 2: Check Resource Availability: verify if the available resources are greater than or equal to the
current needs of each process (Available Resources >= Current Needs). If this condition is not met
for a process (Pi), proceed to the next process (Pi+1). The unsatisfied resources must wait until
there are enough resources to fulfill their needs.

PANGASINAN STATE UNIVERSITY 5


CpE 116 OPERATING SYSTEMS CHAPTER II

Step 3: Successful Termination and Resource Release: when available resources satisfy the current
needs of a process (Pi), that process can successfully terminate its execution. As a result of
termination, the allocated resources held by the process (Pi) are released and returned, increasing
the current available resources. This process of successful termination and resource release can
occur concurrently with other processes.

Current available resources + Released resources = New available resources

Sample Problem:
Given that our system has twelve magnetic tape drives and three processes: P0, P1, and P2. Process
P0 requires up to ten tape drives, process P1 may need as many as four tape drives, and process P2 may
need up to nine tape drives. At time t0, suppose that P0 is holding five tape drives, process p! s holding two
tape drives, and process P2 is holding two tape drives. Thus, there are three free tape drives.

Allocated
Maximum Needs Needs
Resources
P0 10 5 5

P1 4 2 2

P2 9 2 7

Total: 9
Solution:

Given Resources - Total Allocated Resources = Available Resources

12 - 9 = 3

Step 1: For Process P0:


Available ≥ Needs
3 ≥ 5, condition false
So, we will examine another process, P1.

Step 2: For Process P1.


Available ≥ Needs
3 ≥ 2, condition true
New available = Available + Allocated Resources
3+2=5
Now, we again examine the resource request for processes P0.

Step 3: For Process P0:


Available ≥ Needs
5 ≥ 5, condition true
New available = Available + Allocated Resources
5 + 5 = 10
Now, we will examine the last process P2.

Step 4: For Process P2:


Available ≥ Needs
10 ≥ 7, condition true
New available = Available + Allocated Resources

PANGASINAN STATE UNIVERSITY 6


CpE 116 OPERATING SYSTEMS CHAPTER II

10 + 7 = 17

Hence, we found out that the system is in safe state, and this gives us the safe sequence <P1, P0, P2>.

Note: A system can go from a safe state to an unsafe state and a sequence can be changed at any time.

Suppose that, at time t1, process P2 requests and is allocated one more tape drive. The system is no longer
in a safe state.

Allocated
Maximum Needs Needs
Resources
P0 10 5 5

P1 4 2 2

P2 9 3 6

Total: 10

The new value of available resources is 2.

Since process P0 does not satisfy its needs, we will examine the next process P1.
For Process P1.
Available ≥ Needs
2 ≥ 2, condition true
New available = Available + Allocated Resources
2+2=4

Now, we again examine the resource request for processes P0, but as we can see our new available
resources does not satisfy the needs of P0 and P2. This results in both process P0 and P2 to enter in a waiting
state or deadlock, as the required resources are currently unavailable, and they may still have to continue
waiting for resources to be available.

There are given techniques to identify algorithms of the system whether it is safe and if the process
request can be granted to avoid deadlock. Algorithms include Banker’s Algorithm, Safety Algorithm and
Resource-Request Algorithm.

Banker’s Algorithm

This is designed for resource allocation systems that have multiple instances of each resource type. It
is named "Banker's Algorithm" because it could be applied to a banking system to ensure that the bank never
distributes its available cash in a manner that would prevent it from meeting the financial needs of all its
customers.

To maintain the several data structures of the system is to implement banker’s algorithms. These data
structures encode the state of the resource-allocation system. We need the following data structures, where n
is the number of processes in the system and m is the number of resource types:

• Available. A vector of length m indicates the number of available resources of each type. If Available[j]
equals k, then k instances of resource type Rj are available.

PANGASINAN STATE UNIVERSITY 7


CpE 116 OPERATING SYSTEMS CHAPTER II

• Max: An n × m matrix defines the maximum demand of each process. If Max[i][j] equals k, then process Pi
may request at most k instances of resource type Rj.

• Allocation: An n × m matrix defines the number of resources of each type currently allocated to each
process. If Allocation[i][j] equals k, then process Pi is currently allocated k instances of resource
type Rj.

• Need. An n × m matrix indicates the remaining resource need of each process. If Need[i][j] equals k, then
process Pi may need k more instances of resource type Rj to complete its task. Note that Need[i]
[j] equals Max[i][j] − Allocation[i][j].

Safety Algorithm -

We can now present the algorithm for finding out whether a system is in a safe state. This algorithm can be
described as follows:

1. Let Work and Finish be vectors of length m and n, respectively. Initialize Work = Available and Finish[i] =
false for i = 0, 1, ..., n − 1. 2.

2. Find an index i such that both


a. Finish[i] == false
b. Work ≥ Needi
If no such i exists, go to step 4.

3. Work = Work + Allocationi


Finish[i] = true
Go to step 2.

4. If Finish[i] == true for all i, then the system is in a safe state.

Resource-Request Algorithm

We will now delve into the algorithm used to determine whether requests can be safely granted.

Let Requesti be the request vector for process Pi. If Requesti [j] == k, then process Pi wants k instances of
resource type Rj. When a request for resources is made by process Pi, the following actions are taken:

1. If Requesti ≤ Needi, go to step 2. Otherwise, raise an error condition since the process has exceeded its
maximum claim.

2. If Requesti ≤ Available, go to step 3. Otherwise, Pi must wait, since the resources are not available.

3. Have the system pretend to have allocated the requested resources to process Pi by modifying the state as
follows:
Available = Available - Requesti:
Allocationi = Allocationi + Requesti:
Needi = Needi – Requesti:

PANGASINAN STATE UNIVERSITY 8


CpE 116 OPERATING SYSTEMS CHAPTER II

If the resulting resource-allocation state is safe, the transaction is completed, and process Pi is allocated its
resources. However, if the new state is unsafe, then Pi must wait for Requesti, and the old resource-allocation
state is restored.

Sample Problem:

To illustrate the use of the banker’s algorithm, consider a system with five processes P0 through P4 and four
resource types A, B, C, and D. Resource type A has ten instances, resource type B has five instances,
resource type C has seven instances and resource type D has twelve instances. Suppose that, at time T0, the
following snapshot of the system has been taken.
Available + Allocation = New Available
Available ≥ Needs

Maximum Allocated Available


Needs
Needs Resources Resources
A B C D A B C D A B C D A B C D
P0 0 0 1 2 0 0 1 2 0 0 0 0 1 5 2 0
P1 1 7 5 0 1 0 0 0 0 7 5 0
P2 2 3 5 6 1 3 5 4 1 0 0 2
P3 0 6 5 2 0 6 3 2 0 0 2 0
P4 0 6 5 6 0 0 1 4 0 6 4 2

For Process P0,

1,5,2,0 ≥ 0,0,0,0 : Finish[0] = true

1,5,2,0 + 0,0,1,2 = 1,5,3,2

For Process P1,

1,5,3,2 ≥ 0,7,5,0 : Finish[1] = false

So, we will examine another process, P2.

For Process P2,

1,5,3,2 ≥ 1,0,0,2 : Finish[2] = true

1,5,3,2 + 1,3,5,4 = 2,8,8,6

For Process P3,

2,8,8,6 ≥ 0,0,2,0 : Finish[3] = true

2,8,8,6 + 0,6,3,2 = 2,14,11,8

For Process P4,

PANGASINAN STATE UNIVERSITY 9


CpE 116 OPERATING SYSTEMS CHAPTER II

2,14,11,8 ≥ 0,6,4,2 : Finish[4] = true

2,14,11,8 + 0,0,1,4 = 2,14,12,12

Now, we will go back to the process that does not satisfy its needs P1.

For Process P1,

2,14,12,12 ≥ 0,7,5,0 : Finish[1] = true

Hence, the system is in safe state as all the processes are terminated successfully giving us the sequence of
<P0, P2, P3, P4, P1>

Suppose now that process P1 makes three additional requests for an instance of type A. The Request matrix
is modified as follows:

A B C D
Request2 = 1 3 5 5

Maximum Allocated Available


Needs
Needs Resources Resources
A B C D A B C D A B C D A B C D
P0 0 0 1 2 0 0 1 2 0 0 0 0 1 5 2 0
P1 1 7 5 0 3 0 0 0 2 7 5 0
P2 2 3 5 6 1 3 5 4 1 0 0 0
P3 0 6 5 2 0 6 3 2 0 0 2 0
P4 0 6 5 6 0 0 1 4 0 6 4 2

For Process P0,

1,5,2,0 ≥ 0,0,0,0 : Finish[0] = true

1,5,2,0 + 0,0,1,2 = 1,5,3,2

For Process P1,

1,5,3,2 ≥ 2,7,5,0: Finish[1] = false

So, we will examine another process, P2.

For Process P2,

1,5,3,2 ≥ 1,0,0,2 : Finish[2] = true

1,5,3,2 + 1,3,5,4 = 2,8,8,6

For Process P3,

2,8,8,6 ≥ 0,0,2,0 : Finish[3] = true

PANGASINAN STATE UNIVERSITY 10


CpE 116 OPERATING SYSTEMS CHAPTER II

2,8,8,6 + 0,6,3,2 = 2,14,11,8

For Process P4,

2,14,11,8 ≥ 0,6,4,2 : Finish[4] = true

2,14,11,8 + 0,0,1,4 = 2,14,12,12

Now, we will go back to the process that does not satisfy its needs P1.

For Process P1,

2,14,12,12 ≥ 3,7,5,0 : Finish[1] = false

We can now claim that the system is now deadlocked, as the available resources in an instance of type A is
lesser than the needs of resources in instance of type A in process P1.

Safety Algorithm & Resource-Request Algorithm

Deadlock Detection examines the state of the system to determine if any deadlock conditions exist and if the
processes are stuck. If the deadlock is detected, the system will act and recover it, for example, terminating
one of the stuck processes.

Deadlock Detection

 It examines the state of the system to determine if any deadlock conditions exist and if the processes
are stuck. It Blocks the other processes since each process holds the resources until all the resources
have been used.
 If the deadlock is detected, the system will act and recover it, for example, terminating one of the
stuck processes. Once the stuck process is terminated, resources will be free for other processes,
allowing them to continue.

Wait-for-graph is closely related to the resource allocation graph (shown in


figure 1.7). This method only focuses on processes waiting for other
processes.

Node – represents processes.


Edge – (P  Q) process p is waiting for process q to release a
resource.

Figure 1.7 Wait-for-graph


Single Instance of Each Resources Type

 Only one of resources. Since there’s only one resource, it has only one process at a time.
 If all resources have only a single resource type, we can use a wait-for-graph.
 For example, if you have an existing process, wait for that process to end before starting a new one.
 We can use a wait-for-wait graph to keep track of which processes are waiting for others to release
resources.

Several Instance of Each Resources Type

PANGASINAN STATE UNIVERSITY 11


CpE 116 OPERATING SYSTEMS CHAPTER II

 It has multiple resources, which means that allowing multiple processes can occur simultaneously
without waiting for the other process to end.

Detection-Algorithm Usage

The decision to invoke a detection algorithm hinges on two crucial factors. Firstly, the frequency of
deadlock occurrences must be considered. If deadlocks are expected to happen with some regularity, it
becomes imperative to employ a detection algorithm to identify and mitigate them effectively. Secondly, the
scale of the impact matters; one should assess how many processes are likely to be affected by a deadlock
event. This evaluation aids in determining the significance of employing a detection algorithm to safeguard
against potential disruptions caused by deadlocks.

Recovery from Deadlock

Recovery from a deadlock is a critical aspect of managing system stability. When a deadlock occurs,
the primary goal is to resolve it to ensure the affected processes can continue their execution. This can be
achieved through manual intervention by an operator or through automated recovery mechanisms. There are
two primary approaches to breaking a deadlock: process termination and resource preemption. Process
termination involves selectively terminating one or more processes involved in the deadlock, freeing up the
resources they hold and allowing the remaining processes to proceed. On the other hand, resource
preemption involves temporarily reallocating resources from one process to another, effectively breaking the
deadlock and enabling the system to continue functioning smoothly. The choice between these two strategies
depends on the specific system requirements and the criticality of the processes involved.

Process Termination

Process termination is a crucial strategy for resolving deadlocks. There are two primary methods for
eliminating deadlocks by aborting processes. The first method involves abruptly terminating one or more
processes, thereby breaking the circular state, and swiftly resolving the deadlock. While this approach is
quick, it comes with the drawback of potential data loss if critical processes are terminated. In this method, the
system reclaims all resources allocated to the terminated processes.

The second method entails two distinct approaches:

 Abort all deadlocked processes: all processes are terminated simultaneously. It is also used if
there is no priority process. Because if this way is used, important work or data will be lost. It will
remain in an improper condition if you terminate it.
 Abort one process at a time until the deadlock cycle is eliminated: It requires more time. Only
one process is terminated at a time and every termination, it will check if the deadlock is resolved. In
other terms, It only terminates one process at a time, therefore no deadlock is found and addressed
when one process is finished. Until the deadlock is resolved, another process will terminate again.

Resource Preemption

To eliminate deadlocks, it will preempt some resources away from one or more process until the deadlock
cycle is broken.

These are the three issues that needs to be addressed:

• Selecting a victim: Which resources and which processes are to be preempted? When a deadlock is
detected, System needs to decide which process will preempt. As in process termination, the

PANGASINAN STATE UNIVERSITY 12


CpE 116 OPERATING SYSTEMS CHAPTER II

preemption while resolving the deadlock to minimize cost. The goal is to minimize the overall cost
and disruption caused by preemption.

• Rollback: If we preempt a resource from a process, what should be done with that process? If the
victim is already chosen, it must roll back the process to some safe state and restart it from that
state. And if the process is aborted, then it will start from the start.

• Starvation: How do we ensure that starvation will not occur? That is, how can we guarantee that
resources will not always be preempted from the same process? We must ensure that a process
can be picked as a victim only a (small) finite number of times. The most common solution is to
include the number of rollbacks in the cost factor. To avoid starvation, there should be a limit on
the number of times a process can be interrupted.

LEARNING ACTIVITY 1

EXERCISES

LEARNING ACTIVITY 2

QUIZ

SUMMARY

In summary deadlocks occur in the system where multiple processes are waiting to each other for an event
that only one of them can trigger. Dealing with deadlocks involves three main strategies which are deadlock
prevention or avoidance, detection and recovery, and by just ignoring the problem. Deadlock prevention or
avoidance employs protocol to ensure that the system never reaches a deadlock state. On the hand, deadlock
detection and recovery allow deadlocks to occur but has a mechanism to detect them. Once it is identified, the
system takes steps to recover from it, this involves terminating some of the process or preempting resources
from them. The last approach is just to ignore the problem assuming it won’t occur. Deadlocks can only
happen if four necessary conditions hold simultaneously, these are mutually exclusion, hold and wait, no
preemption, and circular wait. To prevent deadlocks, one of these conditions must not be allowed to occur.
Avoiding deadlocks requires a knowledge about how each process will use system resources. A deadlock-
detection algorithm determines if a deadlock has occurred, and if so, the system recovers by terminating
some processes or preempting their resources. Algorithms like the banker’s algorithm help to determine
whether the system is in a safe state. Furthermore, Recovery from deadlock involves breaking the deadlock
by either process termination or resource preemption, depending on system requirements and process
criticality.

REFERENCES

PANGASINAN STATE UNIVERSITY 13


CpE 116 OPERATING SYSTEMS CHAPTER II

Silberschatz, A., Galvin, P. B., & Gagne, G. (2018). Operating system concepts (10th ed.).
Wiley.

GeeksforGeeks. (2023, Sept. 27). Banker's Algorithm in Operating System.


https://www.geeksforgeeks.org/bankers-algorithm-in-operating-system-2/

Computer Science (2016, Nov. 28). Banker's Algorithm explained. Youtube.


https://www.youtube.com/watch?v=T0FXvTHcYi4

Banker's Algorithm in Operating System (OS) – javatpoint.


https://www.javatpoint.com/bankers-algorithm-in-operating-system

PANGASINAN STATE UNIVERSITY 14

You might also like