1、操 作 系 统 课 程 设 计 1 操作系统课程操作系统课程设计设计报告报告 题目:题目:银行家算法银行家算法 院院 (系) :(系) : 计算机科学与工程计算机科学与工程 专专 业:业: 软件工程软件工程 班班 级:级: 学学 生:生: 学学 号:号: 指导教师:指导教师: 2013 年 1 月 操 作 系 统 课 程 设 计 2 目目 录录 摘要摘要 3 3 一一、问题描述、问题描述 4 4 二二、概要设计、概要设计 4 4 2.1 算法思路 4 4 2.2 银行家算法步骤 4 4 2.3 安全性算法步骤 5 5 2.3 各模块间的调用关键 5 5 三、详细设计三、详细设计 5 5 31
2、主要函数的核心代码. 5 5 32 程序流程图. 6 6 四、测试结果及分析四、测试结果及分析 9 9 4.1 用例测试 a 9 9 4.2 用例测试 b 9 9 4.3 用例测试 c 9 9 4.4 用例测试 d 9 9 4.5 用例测试 e . 1010 五五、总结总结 1010 六六、附录附录源代码源代码 1212 操 作 系 统 课 程 设 计 3 银行家算法银行家算法 (西安工业大学计算机科学与工程学院,陕西西安,710021) 摘摘 要要 银行家算法是避免死锁的重要算法,本文介绍了银行家酸价的包括算法思 路、步骤,以及要用到的主要数据结构、函数模块及其之间的调用关系等。在概 要设计
3、的基础上,又给出了详细的算法设计,实现概要设计中定义的所有函数, 对每个函数写出核心算法,并画出了流程图。接着对编码进行了测试与分析(并 在最后附上 Java 编写的程序代码) 。最后对整个设计过程进行了总结。 关键词关键词:安全状态 银行家算法 安全性算法 安全序列 流程图。 Banker s Algorithm Abstract Bankers to avoid deadlock algorithm is an important algorithm, this paper introduces the bankers algorithm, including the steps of a
4、cid value, and to use the main data structure, function module and between the call relation. In the summary of the design basis, and gives a detailed algorithm design, design outline to achieve the definition of all functions, each function to write the core algorithms, and draw the flow chart. The
5、n the coding are tested and analyzed ( and attached in the last Java program code ). The final design of the whole process are summarized. Key Words: safety security sequence bankers algorithm security algorithm flow chart. 操 作 系 统 课 程 设 计 4 1 1、问题描述、问题描述 银行家算法是一种最具有代表性的避免死锁的算法。要解释银行家算法,必 须先解释操作系统的安
6、全状态和不安全状态。所谓安全状态,是指系统能按照某 种进程顺序P1,P2,,Pn(称P1,P2,,Pn 序列为安全序列) ,来为每个进 程 Pi 分配其所需资源,直至满足每个进程对资源的最大需求,使每个进程都可 以顺利完成。 安全状态一定没有死锁发生。 如果系统无法找到这样一个安全序列, 则称系统处于不安全状态。么,什么是安全序列呢?如果对每一个进程 Pi(1135 *此时刻资源分配情况* Number Name Max Allocation Need 0 p0 7 5 3 0 1 0 7 4 3 1 p1 3 2 2 2 0 0 1 2 2 2 p2 9 0 2 3 0 2 6 0 0 3 p3 2 2 2 2 1 1 0 1 1 4 p4 4 3 3 0 0 2 4 3 1 4.4.2 2 用例测试