OPERATING SYSTM’s ALGORITHM (In LINUX OS) - BANKERS ALGORITHM



BANKERS ALGORITHM – SINGLE RESOURCES

PROGRAM:
#include<stdio.h>
main()
{
int j=0,cmp=0,i,tot,avail,need[20],n,tr,max[20],hold[20];
printf("Enter the number of process");
scanf("%d",&n);

printf("Enter the number of resources");
scanf("%d",&tr);

printf("Enter the max,need,hold for each process");
for(i=0;i<n;i++)
{
printf("p%d",i);
scanf("%d",&max[i]);
scanf("%d",&hold[i]);
}
tot=0;
for(i=0;i<n;i++)
{
tot=tot+hold[i];
need[i]=max[i]-hold[i];
}
avail=tr-tot;
while(j!=tr)
{
for(i=0;i<n;i++)
{
if(need[i]!=0&&need[i]<=avail)
{
avail=avail+hold[i];
need[i]=0;
printf("%d\t%d\n",i,avail);
cmp++;
}
}
j++;
}
if(avail==tr)
printf("safe state");
else
printf("unsafe state");
}

Comments

Popular posts from this blog

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE

BOOKS DETAILS USING C STRUCTURE

TRAVELING SALESMAN USING BRANCH AND BOUND TECHNIQUE