Develop a C program to implement the bankers algorithm for deadlock avoidance.
Algorithm:
- Read the following
- Number of processes.
- Number of resources and number of instances of each resource available.
- Maximum requirement of each process,
- Allocated instances of resources
- Determine the need of each process
- Repeat the following till all processes are done.
- Check if request of process i less than or equal to need of that process
- If yes proceed
- Otherwise raise an error condition
- Check if request of process i less than or equal to available instances
- If yes proceed ii. Otherwise wait till available.
- Update the available vector, allocation vector and need vector
- Generate safety sequence by running safety algorithm.
- Check if request of process i less than or equal to need of that process
SAMPLE INPUT & OUTPUT:
Bankers Algorithm
- Read Data
- Print Data
- Safety Sequence 4. Exit
Enter the option :1
Number of processes: 5 P0, P1, P2, P3, P4
Number of resources: 3 A B C
Number of Available instances of A: 3 Number of Available instances of B: 3
Number of Available instances of C: 2
Maximum requirement for P0: 7 5 3
Maximum requirement for P1: 3 2 2
Maximum requirement for P2: 9 0 2
Maximum requirement for P3: 2 2 2
Maximum requirement for P4: 4 3 3
Allocated instances to P0: 0 1 0
Allocated instances to P1: 2 0 0
Allocated instances to P2: 3 0 2
Allocated instances to P3: 2 1 1
Allocated instances to P4: 0 0 2
Enter the option: 2
Alloc Max Need Avail
A B C A B C A B C A B C
P0 0 1 0 7 5 3 * * * 3 3 2
P1 2 0 0 3 2 2 * * *
P2 3 0 2 9 0 2 * * *
P3 2 1 1 2 2 2 * * *
P4 0 0 2 4 3 3 * * *
Enter the option: 3 Display the Safety Sequence:
* * * * *
Enter the option: 4

![[Solved] UCS1411 Exercise 7- Deadlock Avoidance](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] UCS1411 Exercise 2- System calls](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.