Implement the Banker's algorithm.
Input: n m; the Available vector; then n rows of Max; then n rows of Allocation; then zero or more lines request i r1 … rm.
- Print
Need:and one line per process:P0: (7 4 3). - Run the safety algorithm with Work = Available, scanning P0…Pn−1 in passes (in each pass take, in index order, every unfinished process whose Need ≤ Work). For each process taken print
P1 can finish, work = (5 3 2)(two leading spaces, Work after adding its allocation). ThenState: SAFE, sequence P1 P3 P4 P0 P2orState: UNSAFE. - For each request (processed in order; a granted request changes the state), print
Request P1 (1 0 2):followed by:ERROR, exceeds maximum claimif Req > Need (any component);WAIT, resources not availableif Req > Available;GRANTED, safe sequence …, available now (2 3 0)if the pretend-state is safe (no trace lines);DENIED, would be unsafe (P0 waits)otherwise (the state is rolled back).