CS604 - mc210402037
CS604 - mc210402037
To determine if the system is in a safe state we can use the Banker’s Algorithm. This algorithm
helps to decide whether or not the system will enter into a deadlock situation based on the
available resources the allocation of resources and the requests from the processes.
Here are the steps to apply the Bankers’ Algorithm
1. Available Resources = (A, B, C)
Available
A=3
B=2
C=2
2. Allocation Resources
The allocation matrix shows how much if each resources is currently allocated to each process.
Process A B C
P0 0 1 0
P1 2 0 0
P2 3 0 3
P3 2 1 1
P4 0 0 2
3. Requested Resources
The request matrix shows the requested resources for each process.
Process A B C
P0 0 0 1
P1 2 0 2
P2 0 0 0
P3 1 0 0
P4 0 0 2
4. Calculate the Need Matrix
The Need Matrix represents the remaining resources each process needs to finish its execution. It
is calculated as
Need[i] = Request[i] – Allocation[i]
The Need Matrix is as follows:
Process A B C
P0 0 0 1
P1 0 0 2
P2 0 0 0
P3 1 0 0
P4 0 0 0
5. Safety Check
We will now attempt to identify a process whose resource needs can be satisfied by the current
Work vector. If such a process exists, we will mark it as "completed," release its allocated
resources, and add those resources to the Work vector.
Step-by-Step Process:
P0's Need = [0, 0, 1]
Can P0 be satisfied with Work = [3, 2, 2]?
Yes, because P0's Need [0, 0, 1] is less than or equal to [3, 2, 2].
P0 can be completed, and its allocated resources are released.
New Work = Work + Allocation[P0] = [3, 2, 2] + [0, 1, 0] = [3, 3, 2].
P1's Need = [0, 0, 2]
Can P1 be satisfied with Work = [3, 3, 2]?
Yes, because P1's Need [0, 0, 2] is less than or equal to [3, 3, 2].
P1 can be completed, and its allocated resources are released.
New Work = Work + Allocation[P1] = [3, 3, 2] + [2, 0, 0] = [5, 3, 2].
P2's Need = [0, 0, 0]
Can P2 be satisfied with Work = [5, 3, 2]?
Yes, because P2's Need [0, 0, 0] is less than or equal to [5, 3, 2].
P2 can be completed, and its allocated resources are released.
New Work = Work + Allocation[P2] = [5, 3, 2] + [3, 0, 3] = [8, 3, 5].
P3's Need = [1, 0, 0]
Can P3 be satisfied with Work = [8, 3, 5]?
Yes, because P3's Need [1, 0, 0] is less than or equal to [8, 3, 5].
P3's Completion
P3's resources are released, and the Work vector is updated:
P4's Need = [0, 0, 0]
Can P4 be satisfied with Work = [10, 4, 6]?
Yes, because P4's Need [0, 0, 0] is less than or equal to [10, 4, 6].
P4 can be completed, and its allocated resources are released.
New Work = Work + Allocation[P4] = [10, 4, 6] + [0, 0, 2] = [10, 4, 8].
Conclusion: