Theory |
Banker algorithm used to avoid deadlock and allocate resources safely
to each process in the computer system.
Things in Bankers algorithm for each process:
1. [MAX] request.
2. [ALLOCATED] resource.
3. [AVAILABLE] resource.
4. Need[I, j]=Max[I, j]-Allocation[I, j];.
5. Finish
Safety Algorithm
follows the safe sequence in a banker's algorithm
1. Initialize 2 vectors(work and Finish) for safety algorithm.
Work = Available, Finish[i] = false;
for I = 0 to n - 1.
2. Check availability status for each resources [i],
Need[i] <= Work
Finish[i] == false
If the i does not exist, go to step 4.
3. Work = Work +Allocation(i) // to get new resource allocation
Finish[i] = true
Goto step2 to check the status of resource availability for the next process.
4. If Finish[i] == true; indicates system is safe for all processes.
|