版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、操作系统课程设计银行家算法(流程图+源代码+设计报告)一、实验目的:熟悉银行家算法,理解系统产生死锁的原因及避免死锁的方法,加深记意。二、实验要求:用高级语言编写和调试一个描述银行家算法的程序。三、实验内容:1、 设计一个结构体,用于描述每个进程对资源的要求分配情况。包括:进程名name5,要求资源数目commandm(m类资源),还需要资源数目needm,已分配资源数目allom。2、 编写三个算法,分别用以完成:申请资源;显示资源;释放资源。(动态完成)四、程序流程图五、源程序:最新版本:bk5.c/*bk2.c:可以自定义进程及资源数目,可选择读文件或创建新文件,但不超过10,5*/*可
2、修改# define NP 10*/*# define NS 5 */ /*资源种类*/*bk3.c:可以继续分配资源(2)*/*bk4.c:可保存分析结果*/*bk5.c:除以上功能外,对暂时不能分配的可以进行另外一次尝试,并恢复已分配的资源*/*四、程序流程图:五、源程序:最新版本:bk5.c/*bk2.c:可以自定义进程及资源数目,可选择读文件或创建新文件,但不超过10,5*/*可修改# define NP 10*/*# define NS 5 */ /*资源种类*/*bk3.c:可以继续分配资源(2)*/*bk4.c:可保存分析结果*/*bk5.c:除以上功能外,对暂时不能分配的可以进
3、行另外一次尝试,并恢复已分配的资源*/#include string.h#include stdio.h#include dos.h#include conio.h#define MOVEIN 1#define GUIYUE 2#define ACC 3#define OK 1#define ERROR 0#define MAXSH 7#define MAXSHL 10#define MAXINPUT 50#define maxsize 100int act;int ip=0;int line=0; /*line为要写的行号,全局变量*/int writeok;int right;char w
4、el30 = Welcome To Use An_Li System;char ente76= 警告:未经作者同意不得随意复制更改!;char rights40=Copyright (c) 2002;struct date today;struct time now;typedef structint datamaxsize;int top;stack;int emptystack(stack *S)if(S-top=48&S-dataS-top=35)return(1); /*35 is #*/else return(0);int push(stack *S,int x)if(S-top=m
5、axsize-1)return(-1);elseS-top+; S-dataS-top=x; return(0); int gettop(stack *S)return S-dataS-top;int pop(stack *S)if(emptystack(S)printf(the stack is emptyn);exit(1);else S-top-;return S-dataS-top+1;void initstack(stack *S)int i;S-top=0;S-dataS-top=35;/*模拟打字机的效果*/delay_fun() int i; void music(); for
6、(i=0;i+) if(wel!=0) delay(1000); textcolor(YELLOW); gotoxy(26+i,8); cprintf(%c,wel);printf(谢谢);printf(网络 ); music(1,60); else break; delay(); for(i=0; ; i+) if(ente!=0) delay(1000); textcolor(RED);/*显示警告及版权*/ gotoxy(2+i,11); cprintf(%c,ente); music(1,60); else break; delay(40000); for(i=0;i+) if(rig
7、hts != 0) delay(1000); textcolor(YELLOW); gotoxy(30+i,14); cprintf(%c,rights); music(1,60); else break; getch();/*登陆后的效果*/logined() int i; clrscr(); gotoxy(28,10); textcolor(YELLOW); cprintf(程序正在载入 请稍候.); gotoxy(35,12); for(i=0;i=50;i+) gotoxy(40,12); delay(8000); cprintf(%02d%已完成,i*2); gotoxy(i+15,
8、13); cprintf(n); cprintf(|); main0();/*对PC扬声器操作的函数*/void music(int loop,int f) /* f为频率*/ int i;for(i=0;i=0) fprintf(fp,n step: %02d , %s,a,st); writeok=1; fclose(fp);return writeok;int writeerror(char a,char *st) /*错误类型文件*/FILE *fpp;fpp=fopen(an_slr.txt,a);if(fpp=0)printf(nwrite error!);writeok=0;el
9、seif(a=0) fprintf(fpp, %s ,st); /*若a=0 则为添加的注释*/else fprintf(fpp, %s %c(位置:%d) ,st,a,ip+1);writeok=1;fclose(fpp);return writeok;/*/main0()int an,flag=1,action,lenr;char a,wMAXINPUT;int len,s,ss,aa,ana;stack *st;char rMAXSHMAXSHL; /*初始化产生式*/strcpy(r0,S-E);strcpy(r1,E-E+T);strcpy(r2,E-T);strcpy(r3,T-T
10、*F);strcpy(r4,T-F);strcpy(r5,F-(E);strcpy(r6,F-i);clrscr();printf(nplease input analyse string:n);gets(w);len=strlen(w); wlen=#; wlen+1=0;initstack(st);push(st,48); /* (int)0 进栈*/writefile(-1,n-SLR(1)词法分析器-);writefile(-1,n 计本003 安 完成于2003.01.12 14:04);writefile(-1,n谢谢);writefile(-1,网 );writefile(-1,
11、n 以下为串);writefile(-1,w);writefile(-1,(#为系统添加)的分析结果: );writefile(-2, );do s=gettop(st); aa=(int)wip; action=analys(s,aa);if(action=MOVEIN) ss=48+act; push(st,aa); push(st,ss); /* if ss=4 int =52 */ ip+; else if(action=GUIYUE) lenr=strlen(ract)-3; for(an=0;an59)printf(分析出错:ana59!); push(st,ana); /*ana
12、lys(s,aa)即为goto(s,aa) */ if(line+1)%20=0) printf(nThis screen is full,press any key to continue!); getche(); clrscr(); printf( step %02d: %sn,line+,ract); writefile(line,ract);else if(action=ACC) flag=0; right=1;else if(action=ERROR) flag=0; right=0; /*接受 成功*/else flag=0;right=0; /* 出错*/while(flag=1
13、);if(right=1)printf(nok,输入串 %s 为可接受串!,w);if(right=0)printf(nsorry,输入串 %s 分析出错!,w);if(writeok=1)printf(nAnWin soft have wrote a file an_slr.txt); if(right=1)writefile(-1,n最终结果:输入串为可接受串!); main() /*主函数*/ clrscr();delay_fun();logined();六、测试报告操作系统课程设计银行家算法(流程图+源代码+设计报告)六、测试报告:(测试结果保存于系统生成的an.txt 文件中)以下为
14、课本上的实例:- =银行家算法测试结果=- T0 时刻 可用资源(Available) A:3, B:3, C:2 测试日期: 2003-6-28 请求分配时间: 14:07:29 经测试,可为该进程分配资源。以下为资源分配表 资源 Work Need Allocation Work+Alloc Finish ID A B C A B C A B C A B C P01 03 03 02 01 02 02 02 00 00 05 03 02 TRUE P03 05 03 02 00 01 01 02 01 01 07 04 03 TRUE P00 07 04 03 07 04 03 00 01
15、 00 07 05 03 TRUE P02 07 05 03 06 00 00 03 00 02 10 05 05 TRUE P04 10 05 05 04 03 01 00 00 02 10 05 07 TRUE#include string.h#include stdio.h#include dos.h#include conio.h#define MOVEIN 1#define GUIYUE 2#define ACC 3#define OK 1#define ERROR 0#define MAXSH 7#define MAXSHL 10#define MAXINPUT 50#define
16、 maxsize 100int act;int ip=0;int line=0; /*line为要写的行号,全局变量*/int writeok;int right;char wel30 = Welcome To Use An_Li System;char ente76= 警告:未经作者同意不得随意复制更改!;char rights40=Copyright (c) 2002;struct date today;struct time now;typedef structint datamaxsize;int top;stack;int emptystack(stack *S)if(S-top=4
17、8&S-dataS-top=35)return(1); /*35 is #*/else return(0);int push(stack *S,int x)if(S-top=maxsize-1)return(-1);elseS-top+; S-dataS-top=x; return(0); int gettop(stack *S)return S-dataS-top;int pop(stack *S)if(emptystack(S)printf(the stack is emptyn);exit(1);else S-top-;return S-dataS-top+1;void initstac
18、k(stack *S)int i;S-top=0;S-dataS-top=35;/*模拟打字机的效果*/delay_fun() int i; void music(); for(i=0;i+) if(wel!=0) delay(1000); textcolor(YELLOW); gotoxy(26+i,8); cprintf(%c,wel);printf(谢谢);printf(网络 ); music(1,60); else break; delay(); for(i=0; ; i+) if(ente!=0) delay(1000); textcolor(RED);/*显示警告及版权*/ got
19、oxy(2+i,11); cprintf(%c,ente); music(1,60); else break; delay(40000); for(i=0;i+) if(rights != 0) delay(1000); textcolor(YELLOW); gotoxy(30+i,14); cprintf(%c,rights); music(1,60); else break; getch();/*登陆后的效果*/logined() int i; clrscr(); gotoxy(28,10); textcolor(YELLOW); cprintf(程序正在载入 请稍候.); gotoxy(
20、35,12); for(i=0;i=50;i+) gotoxy(40,12); delay(8000); cprintf(%02d%已完成,i*2); gotoxy(i+15,13); cprintf(n); cprintf(|); main0();/*对PC扬声器操作的函数*/void music(int loop,int f) /* f为频率*/ int i;for(i=0;i=0) fprintf(fp,n step: %02d , %s,a,st); writeok=1; fclose(fp);return writeok;int writeerror(char a,char *st)
21、 /*错误类型文件*/FILE *fpp;fpp=fopen(an_slr.txt,a);if(fpp=0)printf(nwrite error!);writeok=0;elseif(a=0) fprintf(fpp, %s ,st); /*若a=0 则为添加的注释*/else fprintf(fpp, %s %c(位置:%d) ,st,a,ip+1);writeok=1;fclose(fpp);return writeok;/*/main0()int an,flag=1,action,lenr;char a,wMAXINPUT;int len,s,ss,aa,ana;stack *st;c
22、har rMAXSHMAXSHL; /*初始化产生式*/strcpy(r0,S-E);strcpy(r1,E-E+T);strcpy(r2,E-T);strcpy(r3,T-T*F);strcpy(r4,T-F);strcpy(r5,F-(E);strcpy(r6,F-i);clrscr();printf(nplease input analyse string:n);gets(w);len=strlen(w); wlen=#; wlen+1=0;initstack(st);push(st,48); /* (int)0 进栈*/writefile(-1,n-SLR(1)词法分析器-);writ
23、efile(-1,n 计本003 安 完成于2003.01.12 14:04);writefile(-1,n谢谢);writefile(-1,网 );writefile(-1,n 以下为串);writefile(-1,w);writefile(-1,(#为系统添加)的分析结果: );writefile(-2, );do s=gettop(st); aa=(int)wip; action=analys(s,aa);if(action=MOVEIN) ss=48+act; push(st,aa); push(st,ss); /* if ss=4 int =52 */ ip+; else if(ac
24、tion=GUIYUE) lenr=strlen(ract)-3; for(an=0;an59)printf(分析出错:ana59!); push(st,ana); /*analys(s,aa)即为goto(s,aa) */ if(line+1)%20=0) printf(nThis screen is full,press any key to continue!); getche(); clrscr(); printf( step %02d: %sn,line+,ract); writefile(line,ract);else if(action=ACC) flag=0; right=1;
25、else if(action=ERROR) flag=0; right=0; /*接受 成功*/else flag=0;right=0; /* 出错*/while(flag=1);if(right=1)printf(nok,输入串 %s 为可接受串!,w);if(right=0)printf(nsorry,输入串 %s 分析出错!,w);if(writeok=1)printf(nAnWin soft have wrote a file an_slr.txt); if(right=1)writefile(-1,n最终结果:输入串为可接受串!); main() /*主函数*/ clrscr();d
26、elay_fun();logined(); 进程 1 申请资源 A:2, B:1, C:1 时的安全性检查 测试日期: 2003-6-28 请求分配时间: 14:07:39 进程请求的资源比Need多!不能为该进程分配资源! 系统在 T0(Request) 时刻是不安全的! -尝试进行另外一个分配- 进程 1 申请资源 A:1, B:0, C:2 时的安全性检查 测试日期: 2003-6-28 请求分配时间: 14:07:55 经测试,可为该进程分配资源。以下为资源分配表 资源 Work Need Allocation Work+Alloc Finish ID A B C A B C A B C A B C P01
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 深度解析(2026)《GBT 297-2015滚动轴承 圆锥滚子轴承 外形尺寸》
- 海洋地质调查员班组安全知识考核试卷含答案
- 丝麻毛纤维预处理工班组安全竞赛考核试卷含答案
- 大型桥梁机械操作工安全综合强化考核试卷含答案
- 硫酸铵生产工班组建设能力考核试卷含答案
- 铁合金特种冶炼工安全宣贯能力考核试卷含答案
- 数字技术驱动农业经济韧性跨区域农业数据共享方案
- 某电子厂生产线优化准则
- 沈阳市大学生创业服务机制的构建与优化研究
- 汽车道路货物运输企业成本剖析与优化策略研究
- 2026中国石油集团昆仑资本有限公司社会招聘笔试模拟试题及答案解析
- 2026年八年级下册地理考试试题及答案
- 小学提高教学质量办法及措施
- 广东省茂名电白区七校联考2026届中考一模数学试题含解析
- 街道督察督办工作制度
- 直播基地规划建设方案报告
- (正式版)DB22∕T 2130-2014 《叶轮式燃气表》
- GB/T 30117.7-2026灯和灯系统的光生物安全第7部分:主要发射可见辐射的光源和灯具
- 2026年教案合集2026年春人教版八年级下册英语Unit 1~Unit 8全册教案新版
- 湖北省武汉市2025-2026学年中考化学模拟精卷(含答案解析)
- 生态环境执法人员跨区域执法协作制度
评论
0/150
提交评论