Exp 7 (Bankers Algo) - A - 05 - Leander Braganza
Exp 7 (Bankers Algo) - A - 05 - Leander Braganza
Experiment - 7
Bankers Algorithm
Algorithm : if
need < available
then
execute the process
New available=Available+Allocation
Else
do not execute go forward
//Need Matrix=Max-Allocation
Data Set : A[m]:Array A of size m shows the number of available
resources.
int n, m, i, j, k;
n = 5; // Number of processes
m = 3; // Number of resources
int alloc[5][3] = { { 0, 1, 0 }, // P0 // Allocation Matrix
{ 2, 0, 0 }, // P1
{ 3, 0, 3 }, // P2
{ 2, 1, 1 }, // P3
{ 0, 0, 2 } }; // P4
int flag = 0;
for (j = 0; j < m; j++) {
if (need[i][j] > avail[j]){
flag = 1;
break;
}
}
if (flag == 0) {
ans[ind++] = i;
for (y = 0; y < m; y++)
avail[y] += alloc[i][y];
f[i] = 1;
}
}
}
}
int flag = 1;
for(int i=0;i<n;i++)
{
if(f[i]==0)
{
flag=0;
printf("The following system is not safe");
break;
}
}
if(flag==1)
{
printf("Following is the SAFE Sequence\n");
for (i = 0; i < n - 1; i++)
printf(" P%d ->", ans[i]);
printf(" P%d", ans[n - 1]);
}
return (0);
Outcome :
References: 1. https://www.geeksforgeeks.org/bankers-algorithm-in-
operating-system-2/
2. https://www.studytonight.com/operating-system/
bankers-algorithm