www.pudn.com > bank.rar > bank.c
#include#define state_ready 0 #define state_waiting -1 #define state_finish 1 #define resource 10 #define process 4 #define inputfile "in.txt" #define outputfile "out.txt" #define maxapply 20 typedef struct pcb { int name ; int state; int current[resource]; int claim[resource]; int allocation[resource]; int flag; }; typedef struct application { int name; int number[resource]; int state; }; struct application apply[maxapply]; struct pcb thepcb[process]; int amount[resource]; int avail[resource]; int napply; FILE*out; /*从in.txt中度入资源总量和各个分配请求*/ int initiate() { FILE*fp; int i,j,n; fp=fopen(inputfile,"r"); for(i=0;i =process) return 1; apply[i].name=n; for(j=0;j amount[j]) return 1; fclose(fp); return 0; } /*把资源请求读入pcb表*/ void readapply(void) { int i,j,n; for(i=0;i ttavail[k]) break; } if(k==resource) { thepcb[j].flag=0; for(k=0;k avail[k]) break; if(k==resource) { fprintf(out,"process %d allocated ",i); thepcb[i].state=state_ready; for(k=0;k