#include
int max1[5][3]={ {7,5,3}, {3,2,2}, {9,0,2}, {2,2,2}, {4,3,3}
};/*最大分配需求矩阵*/ int allocation1[5][3]={ {0,1,0}, {2,0,0}, {3,0,2}, {2,1,1}, {0,0,2}
};/*已分配矩阵*/ int need1[5][3]={ {7,4,3}, {1,2,2}, {6,0,0}, {0,1,1}, {4,3,1} };/*现在需求矩阵*/
int available1[3]={3,3,2};/*现可利用矩阵*/
int max[10][10],allocation[10][10],need[10][10],available[10]; int n_proc;/*进程数*/
int type_src;/*资源种类数*/ int request[10][10];
int work[10];/*可供进程继续运行所需资源的向量*/ int finish[10]; int index[10];
int t=0;/*记录当前的进程数*/
int serial_proc=0;/*当前请求进程*/
/*-------------------------------------------------------------------------------------------------------------*/
/*手动输入时的初始化数据*/ void init0_data(void) {
int i,j;
n_proc=5; type_src=3;
for(i=0;i void proc_require0(void) { int j,tmp; require0: printf(\现在第?进程请求\\n\ scanf(\ if (serial_proc<0 ||serial_proc>=n_proc) { printf(\进程号非法(越界)\\n\ goto require0; } tmp=0; for(j=0;j /*请求资源超过需求资源*/ int over_need() { int j; for(j=0;j /*请求资源超过可利用资源*/ int over_avail() { int j; for(j=0;j /*资源申请成功*/ int apply_success(int be_need,int be_avail) { if (be_need==0 && be_avail==0) { return 1; } return 0; } /*安全性检查*/ int security(int i,int j) { int tmp; for(j=0;j for(i=0;i tmp=1; for(j=0;j for(j=0;j /*银行家算法主体*/ void bank() { int allocation_t[10],available_t[10],need_t[10];/*临时变量*/ int tmp; int j; /*保留当前的资源分配*/ for(j=0;j /*修改available,allocation,need矩阵*/ for(j=0;j

