




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、操作系統(tǒng)課程設(shè)計(jì)銀行家算法(流程圖+源代碼+設(shè)計(jì)報(bào)告)一、實(shí)驗(yàn)?zāi)康模菏煜ゃy行家算法,理解系統(tǒng)產(chǎn)生死鎖的原因及避免死鎖的方法,加深記意。二、實(shí)驗(yàn)要求:用高級語言編寫和調(diào)試一個(gè)描述銀行家算法的程序。三、實(shí)驗(yàn)內(nèi)容:1、 設(shè)計(jì)一個(gè)結(jié)構(gòu)體,用于描述每個(gè)進(jìn)程對資源的要求分配情況。包括:進(jìn)程名name5,要求資源數(shù)目commandm(m類資源),還需要資源數(shù)目needm,已分配資源數(shù)目allom。2、 編寫三個(gè)算法,分別用以完成:申請資源;顯示資源;釋放資源。(動(dòng)態(tài)完成)四、程序流程圖五、源程序:最新版本:bk5.c/*bk2.c:可以自定義進(jìn)程及資源數(shù)目,可選擇讀文件或創(chuàng)建新文件,但不超過10,5*/*可
2、修改# define NP 10*/*# define NS 5 */ /*資源種類*/*bk3.c:可以繼續(xù)分配資源(2)*/*bk4.c:可保存分析結(jié)果*/*bk5.c:除以上功能外,對暫時(shí)不能分配的可以進(jìn)行另外一次嘗試,并恢復(fù)已分配的資源*/*四、程序流程圖:五、源程序:最新版本:bk5.c/*bk2.c:可以自定義進(jìn)程及資源數(shù)目,可選擇讀文件或創(chuàng)建新文件,但不超過10,5*/*可修改# define NP 10*/*# define NS 5 */ /*資源種類*/*bk3.c:可以繼續(xù)分配資源(2)*/*bk4.c:可保存分析結(jié)果*/*bk5.c:除以上功能外,對暫時(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為要寫的行號,全局變量*/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(程序正在載入 請稍候.); 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揚(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();六、測試報(bào)告操作系統(tǒng)課程設(shè)計(jì)銀行家算法(流程圖+源代碼+設(shè)計(jì)報(bào)告)六、測試報(bào)告:(測試結(jié)果保存于系統(tǒng)生成的an.txt 文件中)以下為
14、課本上的實(shí)例:- =銀行家算法測試結(jié)果=- T0 時(shí)刻 可用資源(Available) A:3, B:3, C:2 測試日期: 2003-6-28 請求分配時(shí)間: 14:07:29 經(jīng)測試,可為該進(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為要寫的行號,全局變量*/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(程序正在載入 請稍候.); 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揚(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 申請資源 A:2, B:1, C:1 時(shí)的安全性檢查 測試日期: 2003-6-28 請求分配時(shí)間: 14:07:39 進(jìn)程請求的資源比Need多!不能為該進(jìn)程分配資源! 系統(tǒng)在 T0(Request) 時(shí)刻是不安全的! -嘗試進(jìn)行另外一個(gè)分配- 進(jìn)程 1 申請資源 A:1, B:0, C:2 時(shí)的安全性檢查 測試日期: 2003-6-28 請求分配時(shí)間: 14:07:55 經(jīng)測試,可為該進(jìn)程分配資源。以下為資源分配表 資源 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國仔豬復(fù)合維生素預(yù)混料數(shù)據(jù)監(jiān)測研究報(bào)告
- 2025-2030年中國汽車空調(diào)O型圈數(shù)據(jù)監(jiān)測研究報(bào)告
- 河流堤壩加固施工規(guī)范
- 婚內(nèi)撫養(yǎng)孩子協(xié)議
- 舊門更換成防盜門施工方案
- 面包車高速隧道施工方案
- 施工洞施工方案
- 商場園區(qū)租賃合同管理
- 建設(shè)施工合同講座
- 電子商務(wù)法規(guī)與合規(guī)模擬試卷
- 抵押個(gè)人汽車借款合同范本
- 2025年中考第一次模擬考試地理(青海卷)(全解全析)
- 2025年內(nèi)蒙古電子信息職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫及參考答案
- 2025年內(nèi)蒙古北方職業(yè)技術(shù)學(xué)院單招職業(yè)傾向性測試題庫完美版
- 2025年湖南鐵路科技職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫含答案
- 2025年上海青浦新城發(fā)展集團(tuán)有限公司招聘筆試參考題庫含答案解析
- 四年級組數(shù)學(xué)教學(xué)質(zhì)量提升計(jì)劃
- 園林綠化企業(yè)的職能與工作流程
- Unit 2 Expressing yourself Part A Lets learn Listen and chant(說課稿)-2024-2025學(xué)年人教PEP版(2024)英語三年級下冊
- 水利水電工程(水電站、泵站)運(yùn)行危險(xiǎn)源辨識與風(fēng)險(xiǎn)評價(jià)導(dǎo)則
- 2025年中煤集團(tuán)新疆能源有限公司招聘筆試參考題庫含答案解析
評論
0/150
提交評論