algorithm used in operating systems. It determines whether a deadlock can
occur and why it won't occur. Therefore, we commonly refer to it as a
deadlock detection algorithm to identify potential deadlocks.
For instance, suppose there are three processes, namely P1, P2, and P3.
P1 doesn't have any instances of resource A yet, meaning no CPU has been
allocated to it. P2 indicates its resource demand, while P3 states its
maximum resource needs or demands. Maximum need refers to how many
resources a process requires. The available column shows how many
resources are currently available. If a deadlock exists, we can determine
the safe sequence to avoid it. Safe or unsafe implies that deadlock won't
occur.
We have ten, five, and seven as total available resources. However,
certain resources have already been allocated to specific processes since
we aren't starting at time zero. Subtracting already allocated resources
from maximum needs gives us the remaining need.
Therefore, the algorithm is vital in ensuring the system doesn't
experience deadlocks, which could lead to system crashes or extended
downtime.
Remaining need is the total amount of resources needed by processes p1,
p2, p3, p4, and p5. For example, p2 needs 3 resources of A, but since
nothing has been given yet, its remaining need is still 3.
For p3, its remaining need can be calculated as 6 of resource A, 0 of
resource B, and 22 of resource C. It is important to calculate the
remaining need for each resource based on its respective availability.
The remaining need of all resources should always be equal to or less
than the total available. If this is not the case, then the next process
will be checked.
For instance, the remaining need of p3 is 6 of resource A, 0 of resource
B, and 2 of resource C. If we have 3 of resource A, 0 of resource B, and
2 of resource C available, then p2 can be successfully executed.
The same criterion applies to all processes. A process will only be
successfully executed if its remaining need is less than or equal to the
current availability of resources.
In order to avoid deadlocks in a system, it is important to ensure that
all processes have access to the resources they need for successful
execution. Process p1 is guaranteed all necessary resources for
successful execution, as is process p5. The next process in the sequence
will be p3, and any resources that were previously taken by p3 will be
released.
Deadlock avoidance involves keeping the system well-fed with the
necessary resources, processes, and their respective demands. As long as
there are enough resources available to fulfill the needs of all
processes, deadlock will not occur. If there is a shortage of resources,
the process with the highest priority (i.e. the one that can be
fulfilled) will be given access to those resources first.