Operating Systems Lab Manual / OS Deadlock Prevention Bankers Algorithm C Program

Program Name Write C Program for Operating system Deadlock Prevention Bankers Algorithm
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.

Program
Input
Enter Number of Jobs: 4
Enter Name	and	Time:	a 1
Enter Name	and	Time:	B 4
Enter Name	and	Time:	C 2
Enter Name	and	Time:	D 3
Enter Available	Resources:20
Output
Safe Sequence:
A 1
C 2
D 3
B 4


Home     Back