The Banker's algorithm is used to determine if a system is in a safe state. It calculates the need matrix by subtracting allocation from maximum. It then checks processes one by one to see if available resources are greater than needs, granting requests in that order until all are satisfied or an unsatisfiable need is found, indicating an unsafe state. The example showed the system was safe by granting resources in the sequence P1, P4, P2, P3, P0.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
57 views3 pages
Banker
The Banker's algorithm is used to determine if a system is in a safe state. It calculates the need matrix by subtracting allocation from maximum. It then checks processes one by one to see if available resources are greater than needs, granting requests in that order until all are satisfied or an unsatisfiable need is found, indicating an unsafe state. The example showed the system was safe by granting resources in the sequence P1, P4, P2, P3, P0.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3
Banker algorithm
1. Calculate the content of the need matrix?
2. Check if the system is in a safe state?
Solution
1. The Content of the need matrix can be calculated by using the
formula given below:
Need = Max – Allocation
2. Check if the system is in a safe state?
Safe sequence:
1. For process P0, Need = (3, 2, 1) and
Available = (2, 1, 0) Need <=Available = False So, the system will move to the next process.
2. For Process P1, Need = (1, 1, 0)
Available = (2, 1, 0) Need <= Available = True Request of P1 is granted. Available = Available +Allocation = (2, 1, 0) + (2, 1, 2) = (4, 2, 2) (New Available) 3. For Process P2, Need = (5, 0, 1) Available = (4, 2, 2) Need <=Available = False So, the system will move to the next process. 4. For Process P3, Need = (7, 3, 3) Available = (4, 2, 2) Need <=Available = False So, the system will move to the next process. 5. For Process P4, Need = (0, 0, 0) Available = (4, 2, 2) Need <= Available = True Request of P4 is granted. Available = Available + Allocation = (4, 2, 2) + (1, 1, 2) = (5, 3, 4) now, (New Available) 6. Now again check for Process P2, Need = (5, 0, 1) Available = (5, 3, 4) Need <= Available = True Request of P2 is granted. Available = Available + Allocation = (5, 3, 4) + (4, 0, 1) = (9, 3, 5) now, (New Available) 7. Now again check for Process P3, Need = (7, 3, 3) Available = (9, 3, 5) Need <=Available = True The request for P3 is granted. Available = Available +Allocation = (9, 3, 5) + (0, 2, 0) = (9, 5, 5) 8. Now again check for Process P0, = Need (3, 2, 1) = Available (9, 5, 5) Need <= Available = True So, the request will be granted to P0.
Safe sequence: < P1, P4, P2, P3, P0>
The system allocates all the needed resources to each process. So, we can say that the system is in a safe state.