#include <stdio.h>
int curr[5][5],maxclaim[5][5],avl[5];
int alloc[5]={0,0,0,0,0};
int maxres[5],running[5],safe=0;
int count=0,i,j,exec,r,p;
int main(){
printf("\nEnter the number of resources: ");
scanf("%d",&r);
printf("\nEnter the number of processes: ");
scanf("%d",&p);
for(i=0;i<p;i++){
running[i]=1;
count++;
}
printf("\nEnter Claim Vector: ");
for(i=0;i<r;i++) scanf("%d",&maxres[i]);
printf("\nEnter Allocated Resource Table:\n");
for(i=0;i<p;i++){
for(j=0;j<r;j++) scanf("%d",&curr[i][j]);
}
printf("\nEnter Maximum Claim table:\n");
for(i=0;i<p;i++){
for(j=0;j<r;j++) scanf("%d",&maxclaim[i][j]);
}
printf("\nThe Claim Vector is: ");
for(i=0;i<r;i++) printf("\t%d",maxres[i]);
printf("\nThe Allocated Resource Table:\n");
for(i=0;i<p;i++){
for(j=0;j<r;j++)
printf("\t%d",curr[i][j]);
printf("\n");
}
printf("\nThe Maximum Claim Table:\n");
for(i=0;i<p;i++){
for(j=0;j<r;j++) printf("\t%d",maxclaim[i][j]);
printf("\n");
}
for(i=0;i<p;i++)
for(j=0;j<r;j++) alloc[j]+=curr[i][j];
printf("\nAllocated resources:");
for(i=0;i<r;i++) printf("\t%d",alloc[i]);
for(i=0;i<r;i++) avl[i]=maxres[i]-alloc[i];
printf("\nAvailable resources:");
for(i=0;i<r;i++) printf("\t%d",avl[i]);
printf("\n");
//Main procedure goes below to check for unsafe state.
while(count!=0){
safe=0;
for(i=0;i<p;i++){
if(running[i]){
exec=1;
for(j=0;j<r;j++){
if(maxclaim[i][j]-curr[i][j]>avl[j]){
exec=0;
break;
}
}
if(exec){
printf("\nProcess%d is executing\n",i+1);
running[i]=0;
count--;
safe=1;
for(j=0;j<r;j++) avl[j]+=curr[i][j];
break;
}
}
}
if(!safe){
printf("\nThe processes are in unsafe state.\n");
break;
}else
printf("\nThe process is in safe state");
printf("\nAvailable vector:");
for(i=0;i<r;i++) printf("\t%d",avl[i]);
printf("\n");
}
}
according to wikipendia "The Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes a "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue."
It is called that so that the algorithm will prevent such a financial situation.
step 1: if(need < available) True then, process allocated.. We find new available : old available + allocation step 2: else false go to step 1
Bankers Retardo
platimum bankers platimum bankers platimum bankers
no bankers are not sales people but they are the advisors
A Wunch is what a group of bankers are called.
Bankers Hall was created in 1989.
Dominated by the banking industry, entrepreneurs, bankers said. Do bankers known as: capitalists, investors Bankers means good at breeding in the business vision into business reality of people
They are different because standard algorithm is more common then the expanded algorithm
The Bankers was created in 1975.
Bankers count money and calculate how much to give you.
Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield