Os Ex 7
Os Ex 7
ALGORITHM:
1. Initialize:
- available: array of length R representing available instances of each resource
- max: 2D array of size P x R representing maximum demand of each process
- alloc: 2D array of size P x R representing resources currently allocated to each process
- need: 2D array of size P x R representing remaining need of each process
- finish: array of size P initialized to all zeros
2. Calculate the 'need' matrix by subtracting 'alloc' from 'max' for each process.
5. Loop until all processes are finished or no process can be allocated resources:
a. Find a process i such that 'finish[i] == 0' and 'need[i]' can be satisfied with the available resources.
b. If such a process is found:
i. Mark process i as finished.
ii. Add allocated resources of process i back to 'available'.
iii. Repeat the process until no more processes can be allocated resources.
c. If no such process is found, break the loop.
6. If all processes are finished, the system is in a safe state; otherwise, it's in an unsafe state.