




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、操作系統(tǒng)課程設(shè)計(jì)銀行家算法(流程圖+源代碼+設(shè)計(jì)報(bào)告)一、實(shí)驗(yàn)?zāi)康模菏煜ゃy行家算法,理解系統(tǒng)產(chǎn)生死鎖的原因及避免死鎖的方法,加深記意。二、實(shí)驗(yàn)要求:用高級(jí)語(yǔ)言編寫(xiě)和調(diào)試一個(gè)描述銀行家算法的程序。三、實(shí)驗(yàn)內(nèi)容:1、 設(shè)計(jì)一個(gè)結(jié)構(gòu)體,用于描述每個(gè)進(jìn)程對(duì)資源的要求分配情況。包括:進(jìn)程名name5,要求資源數(shù)目commandm(m類資源),還需要資源數(shù)目needm,已分配資源數(shù)目allom。2、 編寫(xiě)三個(gè)算法,分別用以完成:申請(qǐng)資源;顯示資源;釋放資源。(動(dòng)態(tài)完成)四、程序流程圖五、源程序:最新版本:bk5.c/*bk2.c:可以自定義進(jìn)程及資源數(shù)目,可選擇讀文件或創(chuàng)建新文件,但不超過(guò)10,5*/*可
2、修改# define NP 10*/*# define NS 5 */ /*資源種類*/*bk3.c:可以繼續(xù)分配資源(2)*/*bk4.c:可保存分析結(jié)果*/*bk5.c:除以上功能外,對(duì)暫時(shí)不能分配的可以進(jìn)行另外一次嘗試,并恢復(fù)已分配的資源*/*四、程序流程圖:五、源程序:最新版本:bk5.c/*bk2.c:可以自定義進(jìn)程及資源數(shù)目,可選擇讀文件或創(chuàng)建新文件,但不超過(guò)10,5*/*可修改# define NP 10*/*# define NS 5 */ /*資源種類*/*bk3.c:可以繼續(xù)分配資源(2)*/*bk4.c:可保存分析結(jié)果*/*bk5.c:除以上功能外,對(duì)暫時(shí)不能分配的可以進(jìn)
3、行另外一次嘗試,并恢復(fù)已分配的資源*/#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為要寫(xiě)的行號(hào),全局變量*/int writeok;int right;char w
4、el30 = Welcome To Use An_Li System;char ente76= 警告:未經(jīng)作者同意不得隨意復(fù)制更改!;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;/*模擬打字機(jī)的效果*/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(網(wǎng)絡(luò) ); music(1,60); else break; delay(); for(i=0; ; i+) if(ente!=0) delay(1000); textcolor(RED);/*顯示警告及版權(quán)*/ 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(程序正在載入 請(qǐng)稍候.); 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();/*對(duì)PC揚(yáng)聲器操作的函數(shù)*/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) /*錯(cuò)誤類型文件*/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; /*初始化產(chǎn)生式*/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 進(jìn)棧*/writefile(-1,n-SLR(1)詞法分析器-);writefile(-1,n 計(jì)本003 安 完成于2003.01.12 14:04);writefile(-1,n謝謝);writefile(-1,網(wǎng) );writefile(-1,
11、n 以下為串);writefile(-1,w);writefile(-1,(#為系統(tǒng)添加)的分析結(jié)果: );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(分析出錯(cuò):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; /* 出錯(cuò)*/while(flag=1
13、);if(right=1)printf(nok,輸入串 %s 為可接受串!,w);if(right=0)printf(nsorry,輸入串 %s 分析出錯(cuò)!,w);if(writeok=1)printf(nAnWin soft have wrote a file an_slr.txt); if(right=1)writefile(-1,n最終結(jié)果:輸入串為可接受串!); main() /*主函數(shù)*/ clrscr();delay_fun();logined();六、測(cè)試報(bào)告操作系統(tǒng)課程設(shè)計(jì)銀行家算法(流程圖+源代碼+設(shè)計(jì)報(bào)告)六、測(cè)試報(bào)告:(測(cè)試結(jié)果保存于系統(tǒng)生成的an.txt 文件中)以下為
14、課本上的實(shí)例:- =銀行家算法測(cè)試結(jié)果=- T0 時(shí)刻 可用資源(Available) A:3, B:3, C:2 測(cè)試日期: 2003-6-28 請(qǐng)求分配時(shí)間: 14:07:29 經(jīng)測(cè)試,可為該進(jìn)程分配資源。以下為資源分配表 資源 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為要寫(xiě)的行號(hào),全局變量*/int writeok;int right;char wel30 = Welcome To Use An_Li System;char ente76= 警告:未經(jīng)作者同意不得隨意復(fù)制更改!;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;/*模擬打字機(jī)的效果*/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(網(wǎng)絡(luò) ); music(1,60); else break; delay(); for(i=0; ; i+) if(ente!=0) delay(1000); textcolor(RED);/*顯示警告及版權(quán)*/ 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(程序正在載入 請(qǐng)稍候.); 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();/*對(duì)PC揚(yáng)聲器操作的函數(shù)*/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、 /*錯(cuò)誤類型文件*/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; /*初始化產(chǎn)生式*/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 進(jìn)棧*/writefile(-1,n-SLR(1)詞法分析器-);writ
23、efile(-1,n 計(jì)本003 安 完成于2003.01.12 14:04);writefile(-1,n謝謝);writefile(-1,網(wǎng) );writefile(-1,n 以下為串);writefile(-1,w);writefile(-1,(#為系統(tǒng)添加)的分析結(jié)果: );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(分析出錯(cuò):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; /* 出錯(cuò)*/while(flag=1);if(right=1)printf(nok,輸入串 %s 為可接受串!,w);if(right=0)printf(nsorry,輸入串 %s 分析出錯(cuò)!,w);if(writeok=1)printf(nAnWin soft have wrote a file an_slr.txt); if(right=1)writefile(-1,n最終結(jié)果:輸入串為可接受串!); main() /*主函數(shù)*/ clrscr();d
26、elay_fun();logined(); 進(jìn)程 1 申請(qǐng)資源 A:2, B:1, C:1 時(shí)的安全性檢查 測(cè)試日期: 2003-6-28 請(qǐng)求分配時(shí)間: 14:07:39 進(jìn)程請(qǐng)求的資源比Need多!不能為該進(jìn)程分配資源! 系統(tǒng)在 T0(Request) 時(shí)刻是不安全的! -嘗試進(jìn)行另外一個(gè)分配- 進(jìn)程 1 申請(qǐng)資源 A:1, B:0, C:2 時(shí)的安全性檢查 測(cè)試日期: 2003-6-28 請(qǐng)求分配時(shí)間: 14:07:55 經(jīng)測(cè)試,可為該進(jìn)程分配資源。以下為資源分配表 資源 Work Need Allocation Work+Alloc Finish ID A B C A B C A B C A B C P01
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 民情大調(diào)研活動(dòng)方案
- 植樹(shù)活動(dòng)暨捐款活動(dòng)方案
- 檢察院迎春送?;顒?dòng)方案
- 愛(ài)少先隊(duì)班會(huì)課件
- 槐米提取物槲皮素及其與粘桿菌素聯(lián)合使用對(duì)沙門氏菌的抑制效果
- 基于5W1H分析法的科研檔案知識(shí)管理系統(tǒng)構(gòu)建與優(yōu)化策略研究
- 綠色理念驅(qū)動(dòng)下的“零廢棄”工廠建設(shè)策略
- 數(shù)字化教育環(huán)境下高校美育模式的創(chuàng)新與探索
- 地理標(biāo)志農(nóng)產(chǎn)品品牌建設(shè)問(wèn)題與對(duì)策研究
- 陳列設(shè)計(jì)師崗位面試問(wèn)題及答案
- GB/T 39866-2021建筑門窗附框技術(shù)要求
- GB/T 3836.2-2021爆炸性環(huán)境第2部分:由隔爆外殼“d”保護(hù)的設(shè)備
- 關(guān)節(jié)脫位患者的護(hù)理-關(guān)節(jié)脫位患者的護(hù)理(外科護(hù)理ppt)
- 產(chǎn)品合格證模板-合格證模板樣本
- 領(lǐng)導(dǎo)干部的決策力與執(zhí)行力
- 水泵試運(yùn)行調(diào)試記錄
- 半導(dǎo)體中載流子的統(tǒng)計(jì)分布和計(jì)算
- 組織部處級(jí)干部培訓(xùn)審計(jì)財(cái)經(jīng)紀(jì)律課件
- 史上最全最權(quán)威婦產(chǎn)科icd編碼培訓(xùn)【版】課件
- 心血管診治與搶救標(biāo)準(zhǔn)操作規(guī)程(SOP)
- 中南大學(xué)自主招生綜合素質(zhì)測(cè)試面試試題答題技巧
評(píng)論
0/150
提交評(píng)論