import java.util.Scanner;
public class Test
{
int no1, no2; //进程、资源个数
static int Max[][]; //最大需求
static int Allocation[][]; //已分配资源数
static int Need[][]; //仍需资源数
static int Available[]; //可利用资源数
static String name1[]; //进程名称
static String name2[]; //资源名称
static boolean[] Finish;
static int[] temp = { 0 }; //存放安全序列
static int work[];
static int[] Request;
Scanner input = new Scanner(System.in);
public static void main(String[] args) {
Test t = new Test();
t.printFrame();
//t.print();
t.Safty();
t.judge();
}
/* 输入初始化数据*/
public void printFrame()
{
System.out.println("*****************************************************");
System.out.println("* 银行家算法设计与实现 *");
System.out.println("* 学号: *");
System.out.println("* 姓名: *");
System.out.println("* *");
System.out.println("*****************************************************");
System.out.print("请输入系统中进程的个数:");
no1 = input.nextInt();
System.out.print("请输入资源的种类数:");
no2 = input.nextInt();
Max = new int[no1][no2];
Allocation = new int[no1][no2];
Need = new int[no1][no2];
Available = new int[no2];
name1 = new String[no1];
name2 = new String[no2];
//int sum[] = new int[3];
for (int i = 0; i < no1; i++)
{
System.out.print("请输入进程" + i + "的名字:");
name1[i] = input.next();
}
for (int i = 0; i < no2; i++)
{
System.out.print("请输入资源" + i + "的名字:");
name2[i] = input.next();
}
for (int i = 0; i < no1; i++)
{
System.out.print("请输入进程" + name1[i] + "的各类资源最大需求量:");
for (int j = 0; j < no2; j++)
{
Max[i][j] = input.nextInt();
}
}
for (int i = 0; i < no1; i++)
{
System.out.print("请输入进程" + name1[i] + "的各类资源已分配资源量:");
for (int j = 0; j < no2; j++)
{
Allocation[i][j] = input.nextInt();
Need[i][j] = Max[i][j] - Allocation[i][j];
}
}
for (int i = 0; i < no2; i++)
{
System.out.print("请输入" + name2[i] + "类资源的可利用资源数:");
Available[i] = input.nextInt();
}
//for (int i = 0; i < no2; i++)
// {Available[i] = Available[i] - sum[i];}
}
/**
* 打印输出
*/
public void print()
{
System.out.println("================此时刻资源分配情况================");
System.out.println(" Number Name Max Allocation Need");
for (int i = 0; i < no1; i++)
{
System.out.print( " "+ i +" ");
System.out.print(name1[i]+" ");
for (in
操作系统银行家算法_工学_高等教育_教育专区。操作系统银行家算法[操作系统 银行家算法操作系统实验报告 操作系统] 操作系统实验目标 1. 2. 3. 4. 理解银行家...
银行家算法例子+答案。软件工程1、设系统中有 3 种类型的资源(A,B,C)和 5 个进程 P1、P2、P3、P4、P5,A 资源的数量为 17,B 资源的数量为 5,C ...
计算机学院《操作系统》课程设计报告 设计题目:银行家算法的实现 姓名: 学号: 班级: 06 网络工程班 完成日期: 2009 年 6 月 13 日 设计题目 设计形式 银行家...
22、在银行家算法中, 22、在银行家算法中,若出现下 述资源分配情况: 述资源分配情况: Process Allocation P0 P1 P2 P3 P4 0032 1000 1354 0332 0014 ...
(20) 刘立波 耿瑜 鲁静轩 合作者: 指导教师: 2009 年 6 月 10 日 1 操作系统课程设计任务书 操作系统课程设计任务书一、题目:银行家算法 题目: 二、设计...
银行家算法( 学时) 实验 2 银行家算法(2 学时)一、实验目的 理解银行家算法,掌握进程安全性检查的方法及资源分配的方 法。 二、实验内容 编写程序实现银行家...
书签。 摘要银行家算法是一种最有代表性的避免死锁的算法, 在避免死锁方 法中允许进程动态的申请资源,但系统在进行资源分配之前,应先计 算此次分配资源的安全性...
学校代码: 学校代码: 学号: 10128 200920201076 课程设计题 学系专班目:银行家算法的设计与实现 院:信息工程学院 别:计算机系 业:计算机科学与技术 级:计算机 09...
银行家算法例题_工学_高等教育_教育专区。银行家算法例题 银行家算法例题 假定系统中有五个进程{P0, ,,, 和三类资源{A ,B,C},各种资源的数量分别 假定系统...
成绩 课程设计报告 课程设计报告 题 目 银行家算法程序设计 银行家算法程序设计 课程名称院部名称专班业级 操作系统课程设计 操作系统课程设计 信息技术学院 计算机...
热门文档