课程设计-银行家算法的设计与实现.docx_第1页
课程设计-银行家算法的设计与实现.docx_第2页
课程设计-银行家算法的设计与实现.docx_第3页
课程设计-银行家算法的设计与实现.docx_第4页
课程设计-银行家算法的设计与实现.docx_第5页
已阅读5页,还剩15页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

内蒙古工业大学操作系统课程设计学校代码: 10128学 号: 200810205004课程设计题 目:银行家算法的设计与实现 学生姓名:朱见涛 学 院:信息工程学院系 别:计算机系 专 业:软件工程 班 级:软08-1指导教师:秦俊平 讲师马志强 讲师20011年1月18日 18内蒙古工业大学课程设计任务书(二)学院(系):信息学院计算机系 课程名称:操作系统课程设计 指导教师(签名): 专业班级: 软件工程 081 学生姓名: 朱见涛 学号: 200810205004 一、课程设计题目银行家算法的设计与实现二、课程设计的目的通过银行家算法设计与实现,可以加深学生对死锁的理解,掌握死锁的预防、避免、检测和解除的基本原理,重点掌握死锁的避免方法银行家算法。使学生初步具有研究、设计、编制和调试操作系统模块的能力。 三、课程设计的主要内容和要求(包括原始数据、技术参数、设计要求、工作量要求等) 技术参数: windows xp系统,vc+6.0开发工具。设计要求: 1 设计银行家算法的核心数据结构、安全性检查算法;2 画出银行家算法流程图;3 编程实现算法功能;4 编写课程设计说明书。 工作量要求:完成以上设计要求中的所有算法功能。四、工作进度安排 周一:布置、讲解题目,收集资料;周二:系统分析,算法设计;周三:编制、调试程序;周四:测试系统,形成设计结论,编写课设报告;周五:系统及材料验收,课设答辩。五、主要参考文献1 张尧学编计算机操作系统教程(第三版)习题解答与实验指导北京:清华大学出版社,20062 汤子瀛主编计算机操作系统(第三版)西安:西安电子科技大学出版社,2001 3 张坤等编操作系统实验教程北京:清华大学出版社,2008审核批准意见系(教研室)主任(签字) 目 录第一章设计内容111 设计目的112 设计要求113 程序设计思想1第二章 数据结构、算法和算法流程图221 数据结构222 程序功能图223 程序流程图3第三章 程序运行结果及分析631 程序运行结果632 程序分析7第四章 心得体会8参考文献9附录 程序清单10第一章 设计内容11 设计目的通过银行家算法设计与实现,可以加深学生对死锁的理解,掌握死锁的预防、避免、检测和解除的基本原理,重点掌握死锁的避免方法银行家算法。使学生初步具有研究、设计、编制和调试操作系统模块的能力。12 设计要求1.问题描述银行家算法是一种最有代表性的避免死锁的算法。在避免死锁方法中允许进程动态的申请资源,但系统在进行资源分配之前,应先计算此次分配资源的安全性,若分配不会导致系统进入不安全状态,则分配,否则等待。要解释银行家算法,必须先解释操作系统安全状态和不安全状态。安全序列是指一个进程序列p1,pn是安全的,如果对于每一个进程pi(1in),它以后尚需要的资源量不超过系统当前剩余资源量与所有进程pj (j i )当前占有资源量之和。安全状态:如果存在一个由系统中所有进程构成的安全序列p1,pn,则系统处于安全状态。安全状态一定是没有死锁发生。不安全状态:不存在一个安全序列。不安全状态不一定导致死锁。我们可以把操作系统看作是银行家,操作系统管理的资源相当于银行家管理的资金,进程向操作系统请求分配资源相当与用户向银行家贷款。操作系统按照银行家指定的规则为进程分配资源,当进程首次申请资源时,要测试该进程对资源的最大需求量,如果系统现存的资源可以满足他的最大需求量则按当前的申请量分配资源,否则就推迟分配。当进程在执行中继续申请资源时,先测试该进程已占用的资源数与本次申请的资源数之和是否超过了该进程对资源的最大需求量。若超过则拒绝分配资源,若没有超过则再测试系统现存的资源能否满足该进程尚需的最大资源量,若能满足则按当前的申请量分配资源,否则也要推迟分配。2.基本要求1)分析设计内容,给出解决方案(要说明设计实现的原理,采用的数据结构)。2)画出程序的基本结构框图和流程图。3)对程序的每一部分要有详细的设计分析说明。4)源代码格式要规范。5)设计合适的测试用例,队得到的运行结果要有分析。6)设计中遇到的问题,设计的心得体会。7)按期提交完整的程序代码,可执行程序和课程设计报告。1.3 程序设计思想1.设计思想输入当前进程资源的使用情况以及整个系统的资源使用情况,并进行初始化安全性检查;如果是不安全状态,重新初始化系统;否则,从等待队列中提取一个等待进程,使用银行家算法进行检测,输出当前系统的状态和安全序列;如果是安全状态,系统继续从等待队列中提取等待进程进行检查;如果是不安全状态,进程回到等待队列,系统从等待队列中提取等待进程进行检查。系统中申请资源的进程全部进入等待队列等候处理。第二章 数据结构、算法和算法流程图21 数据结构银行家算法中用到的主要数据结构可用资源向量 int availablei /j为资源的种类最大需求矩阵 int maxij /i为进城的数量分配矩阵 int allocationij 需求矩阵 int needij=maxij-allocationij申请各类资源数量 int requestij /i申请j资源的数量工作向量 int worki int finishi安全序列 int pi22 程序功能图银行家算法系统显示分配资源状态资源分配安全性检查初始化资源银行家算法实现资源分配显示安全序列图2.1文件系统提供的文件操作有建立文件(mkfile)、复制文件(copy)、显示文件所有内容(type)、删除文件(delfile)。可以通过键盘输入命令来模拟文件的操作。23 程序流程图(1)主程序流程图:图2.1第三章 程序运行结果及分析31 程序运行结果(1)初始化界面图3.1(2)检测系统资源分配是否安全(若安全,输入安全序列)图3.2图3.332 程序分析本程序依靠键盘输入初始化系统资源数量及种类,有银行家算法检验系统资源是否安全,输出安全序列。提出请求requesti,同意分配,则进行安全性算法safe(),否则输出提示:请求被拒绝。直到所有进程finish=true,安全且输出安全序列,安全算法safe()结束。第四章 心得体会通过本次的课程设计,使我能够正确运用操作系统课程中所学的基本理论和知识。操作系统的基本特征是并发与共享。系统允许多个进程并发执行,并且共享系统的软、硬件资源。为了最大限度的利用计算机系统的资源,操作系统应采用动态分配的策略,但是这样就容易因资源不足,分配不当而引起“死锁”。而我本次课程设计就是得用银行家算法来避免“死锁”。银行家算法是一个分配资源的过程,是分配的序列不会产生死锁。此算法的中心思想是:按该法分配资源时,每次分配后总存在着一个进程,如果让它单独运行下去,必然可以获得它所需要的全部资源,也就是说,它能结束,而它结束后可以归还这类资源以满足其他申请者的需要。本次程序就是按照上面的思路展开的。但是因为时间上的仓促,本课程设计存在以下不足:一、不能实现并发操作,即当总资源同时满足几个进程所需要的资源数时,这些进程不能同时进行,只能一一按进程顺序执行。二、扫描进程顺序单一,只能按进程到来的顺序来扫描,从而产生的安全序列只能是在这个顺序的基础上产生的,而其实安全序列是有多个的。三、对进程数和资源数进行的数量进行了限制,都只能最多有十个。四、运行程序后,界面较差,进程数,所需要资源数,已分配资源数,能用资源数,不能一目了然。设计一个软件,先要做好需求分析,这一点很重要,如果没有分析好需求,到软件设计的最后,发现所做的功能不符合要求,那么一切都得重做。还有比较重要的是,画好程流程图。在编程和调试的过程中,经常会出现意想不到的问题,并非每个问题都可以从相关资料中找到解决方法,有些问题是无法预料到的,这就需要通过自己理性的分析得出问题的解决方案。在设计过程中,查询了不少相关资料,不断的发现问题、提出问题、解决问题。总的来说通过这次的设计的学习使我学到了很多在平时的学习中学不到的很多东西,通过这次课程设计,使我学到了很多的实用性知识。除了更深的了解这个算法,而且对c语言进行了复习,而且其过程中有很多的知识点都不记得了,所以在此感谢在此过程中帮助过我的老师和同学。参考文献1 张尧学编计算机操作系统教程(第三版)习题解答与实验指导北京:清华大学出版社,20062 汤子瀛主编计算机操作系统(第三版)西安:西安电子科技大学出版社,2001 3 csdn论坛4 张丽芬等编操作系统实验教程北京:清华大学出版社,2006附录 程序清单#include using namespace std;#define maxprocess 10 /*最大进程数*/#define maxresource 10 /*最大资源数*/int availablemaxresource; /*可用资源数组*/int maxmaxprocessmaxresource; /*最大需求矩阵*/int allocationmaxprocessmaxresource; /*分配矩阵*/int needmaxprocessmaxresource; /*需求矩阵*/int requestmaxprocessmaxresource; /*进程申请资源数*/bool finishmaxprocess; /*系统是否有足够的资源分配*/int pmaxprocess; /*记录序列*/int m,n; /*m个进程,n个资源*/void init();bool safe();void bank();int main() init(); safe(); bank();void init() /*初始化算法*/ int i,j; printf(请输入进程的数目:); scanf(%d,&m); printf(请输入资源的种类:); scanf(%d,&n); printf(请输入每个进程最多所需的各资源数,按照%dx%d矩阵输入n,m,n); for(i=0;im;i+) for(j=0;jn;j+) scanf(%d,&maxij); printf(请输入每个进程已分配的各资源数,也按照%dx%d矩阵输入n,m,n); for(i=0;im;i+) for(j=0;jn;j+) scanf(%d,&allocationij); needij=maxij-allocationij; if(needij0) printf(您输入的第%d个进程所拥有的第%d个资源数错误,请重新输入:n,i+1,j+1); j-; continue; printf(请输入各个资源现有的数目:n); for(i=0;in;i+) scanf(%d,&availablei); void bank() /*银行家算法*/ int i,cusneed; char again; while(1) printf(请输入要申请资源的进程号(注:第1个进程号为0,依次类推)n); scanf(%d,&cusneed); printf(请输入进程所请求的各资源的数量n); for(i=0;in;i+) scanf(%d,&requestcusneedi); for(i=0;ineedcusneedi) printf(您输入的请求数超过进程的需求量!请重新输入!n); continue; if(requestcusneediavailablei) printf(您输入的请求数超过系统有的资源数!请重新输入!n); continue; for(i=0;in;i+) availablei-=requestcusneedi; allocationcusneedi+=requestcusneedi; needcusneedi-=requestcusneedi; if(safe() printf(同意分配请求!n); else printf(您的请求被拒绝!n); for(i=0;in;i+) availablei+=requestcusneedi; allocationcusneedi-=requestcusneedi; needcusneedi+=requestcusneedi; for(i=0;im;i+) finishi=false; printf(您还想再次请求分配吗?是请按y/y,否请按其它键n); scanf(%d,&again); if(again=y|again=y) continue; break; bool safe() /*安全性算法*/ int i,j,k,l=0; int workmaxresource; /*工作数组*/ for(i=0;in;i+) worki=availablei; for(i=0;im;i+) finishi=false; for(i=0;im;i+) if(finishi=true) continue; else for(j=0;jworkj) break; if(j=n) finishi=true; for(k=0;kn;k+) workk+=allocationik; pl+=i; i=-1; else continue; if(l=m) printf(系统是安全的n); printf(安全序列:n); for(i=0;i); printf(n); return true; printf(系统是不安全的n); return false; g an employment tribunal claiemployment tribunals sort out disagreements between employers and employees.you may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.for more information about dismissal and unfair dismissal, seedismissal.you can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. however, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. if your application is received after this time limit, the tribunal will not usually accept i.if you are worried about how the time limits apply to you, take advice from one of the organisations listed underfurther help.employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.most people find making a claim to an employment tribunal challenging. if you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underfurther help.if you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. this is known as adamages-based agreement. in england and wales, your solicitor cant charge you more than 35% of your compensation if you win the case.if you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. it might be best to get advice from an experienced adviser, for example, at a citizens advice bureau. to find your nearest cab, including those that give advice by e-mail, click onnearest cab.for more information about making a claim to an employment tribunal, seeemployment tribunals.the (lack of) air up there watch mcayman islands-based webb, the head of fifas anti-racism taskforce, is in london for the football associations 150th anniversary celebrations and will attend citys premier league match at chelsea on sunday.i am going to be at the match tomorrow and i have asked to meet yaya toure, he told bbc sport.for me its about how he felt and i would like to speak to him first to find out what his experience was.uefa hasopened disciplinary proceedings against cskafor the racist behaviour of their fans duringcitys 2-1 win.michel platini, president of european footballs governing body, has also ordered an immediate investigation into the referees actions.cska said they were surprised and disappointed by toures complaint. in a statement the russian side added: we found no racist insults from fans of cska.age has reached the end of the beginning of a word. may be guilty in his seems to passing a lot of different life became the appearance of the same day; may be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. always feel oneself should go to do something, or write something. twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。the end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?during my childhood, think lucky money and new clothes are necessary for new year, but as the advance of the age, will be more and more found that those things are optional; junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。a persons time, your ideas are always special to clear. want, want, line is clear, as if nothing could shake his. also once seemed to be determined to do something, but more often is he backed out at last. dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。at the moment, the sky is dark, the air is fresh factor after just rained. suddenly thought of blue plaid shirt; those were broken into various shapes of stationery; from the corner at the beginning of deep friendship; have declared the end of the encounter that havent start planning. those years, those days of do, finally, like youth, will end in our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。baumgartner the disappointing news: mission aborted. r plays an important role in this mission. starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. the balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. it will climb higher than the tip of mount everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. as he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.the supersonic descent could happen as early as sunda.the weathethe balloon will slowly drift to the edge of space at 120,000

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论