//Bankers Algorithm
Program :
#include<stdio.h>
#define true 1
#define false 0
int m,n,i,j,count=0,process;
int max[10][10],alloc[10][10],need[10][10],c[10],avail[10],finish[10];
void readtable(int t[10][10])
{
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d",&t[i][j]);
}
void printtable(int t[10][10])
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("\t%d",t[i][j]);
printf("\n");
}
}
void readvector(int v[10])
{
for(j=0;j<n;j++)
scanf("%d",&v[j]);
}
void printvector(int v[10])
{
for(j=0;j<n;j++)
printf("\t%d",v[j]);
}
void init()
{
printf("enter the number of process\n");
scanf("%d",&m);
printf("enter the number of resources\n");
scanf("%d",&n);
printf("enter the claim table\n");
readtable(max);
printf("enter the allocation table\n");
readtable(alloc);
printf("enter the max units of each resource\n");
readvector(c);
for(i=0;i<n;i++)
finish[i]=false;
}
void findavail()
{
int sum;
for(j=0;j<n;j++)
{
sum=0;
for(i=0;i<m;i++)
{
sum=sum+alloc[i][j];
}
avail[j]=c[j]-sum;
}
}
void findneed()
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
need[i][j]=max[i][j]-alloc[i][j];
}
}
}
void selectprocess()
{
int flag;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(need[i][j]<=avail[j])
flag=1;
else
{
flag=0;
break;
}
}
if((flag==1)&&(finish[i]==false))
{
process=i;
count++;
break;
}
}
printf("current status is\n");
printtable(alloc);
if(flag==0)
{
printf("system is in unsafe state\n");
exit(1);
}
printf("system is in safe state");
}
void executeprocess(int p)
{
printf("excuting process is %d",p);
printtable(alloc);
}
void releaseresource()
{
for(j=0;j<n;j++)
avail[j]=avail[j]+alloc[process][j];
for(j=0;j<n;j++)
{
alloc[process][j]=0;
need[process][j]=0;
}
}
main()
{
init();
findavail();
findneed();
do
{
selectprocess();
finish[process]=true;
executeprocess(process);
releaseresource();
}while(count<m);
printf("\n all proces executed correctly");
}
Thank Q
ReplyDeletethnx....
ReplyDeletethnx
ReplyDeletethanqqqq uuu so muchh luv :*
ReplyDeletewhat the hell is this.........
ReplyDeleteDetailed program visit
ReplyDeleteproud2bengineer.blogspot.com
thnxxx...
ReplyDeletethanx
ReplyDeletethnqqqqqqqqqqqqqqq
ReplyDeletebosssssssssss
chothe it is!!!!!!!!!!!!!
ReplyDeletethnku :) :) :)
ReplyDeletevandanegalu :))
ReplyDeleteDetailed program visit
ReplyDeleteproud2bengineer.com
thank you
ReplyDeleteGreat and Useful Article.
ReplyDeleteJava Online Course
Java Online Training
Java EE training
Java Course in Chennai
Java Training in Chennai
Java Training Institutes in Chennai
Java Interview Questions
Java Interview Questions
Great! i like your post so much stick-rpg2.com
ReplyDeletegreat article, I was very impressed about it, wish you would have stayed next share
ReplyDeletewww.appbaixar.com
I was very impressed by this post, this site has always been pleasant news. Thank you very much for such an interesting post. Keep working, great job! In my free time, I like play game: mutilateadoll2game.com. What about you?
ReplyDeleteAlot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. Nice! thank you so much! Thank you for sharing.
ReplyDeletewww.baixar-whatsapp-gratis.com.br
Here is a good Weblog You might Come across Fascinating that we Encourage You
ReplyDeleteโปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
สมัครสล็อตออนไลน์ >>> goldenslot
สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย
ReplyDeleteEnjoyed studying this, very good stuff, thanks.
เว็บไซต์คาสิโนออนไลน์ที่ได้คุณภาพอับดับ 1 ของประเทศ
เป็นเว็บไซต์การพนันออนไลน์ที่มีคนมา สมัคร Gclub Royal1688
และยังมีหวยให้คุณได้เล่น สมัครหวยออนไลน์ ได้เลย
สมัครสมาชิกที่นี่ >>> Gclub Royal1688
ร่วมลงทุนสมัครเอเย่นคาสิโนกับทีมงานของเราได้เลย