版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、 操作系統(tǒng)實(shí)驗(yàn)(2) 實(shí)驗(yàn)題目:作 業(yè) 調(diào) 度 實(shí) 驗(yàn)課程名稱:操 作 系 統(tǒng) 學(xué) 院: 專業(yè)班級: 學(xué) 號(1): 姓 名(1): 學(xué) 號(2): 姓 名(2): 任課教師: 2010年4月12日學(xué)院:管 理 學(xué) 院 班級: 組員: 組員: 評定: 實(shí)驗(yàn)題目:作業(yè)調(diào)度實(shí)驗(yàn)(1) 實(shí)驗(yàn)?zāi)康模河酶呒壵Z言編寫和調(diào)試一個或多個作業(yè)調(diào)度的模擬程序,以加深對作業(yè)調(diào)度算法的理解。(2)實(shí)驗(yàn)內(nèi)容:編寫并調(diào)試一個單道處理系統(tǒng)的作業(yè)等待模擬程序。作業(yè)等待算法:分別采用先來先服務(wù)(FCFS),最短作業(yè)優(yōu)先(SJF)、響應(yīng)比高者優(yōu)先(HRN)的調(diào)度算法。對每種調(diào)度算法都要求打印每個作業(yè)開始運(yùn)行時刻、完成時刻、周轉(zhuǎn)時
2、間、帶權(quán)周轉(zhuǎn)時間,以及這組作業(yè)的平均周轉(zhuǎn)時間及帶權(quán)平均周轉(zhuǎn)時間,以比較各種算法的優(yōu)缺點(diǎn)。(3) 源代碼(含注釋):先來先服務(wù)(FCFS):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define NULL 0 struct jcb /* 定義作業(yè)控制塊PCB */ char name10; char state; int ttime; int ntime; int rtime; int otime; int etime; float zztime; float dqtim
3、e; struct jcb* link; *ready=NULL,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb JCB; void sort() /* 建立對進(jìn)程進(jìn)行提交時間排列函數(shù)*/ JCB *first, *second; int insert=0; if(ready=NULL)|(p-ttime)ttime) /*提交時間最大者,插入隊(duì)首*/ p-link=ready; ready=p; else /* 進(jìn)程比較提交時間,插入適當(dāng)?shù)奈恢弥?/ first=ready;
4、 second=first-link; while(second!=NULL) if(p-ttime)ttime) /*若插入進(jìn)程比當(dāng)前提交時間早*/ /*插入到當(dāng)前進(jìn)程前面*/ p-link=second; first-link=p; second=NULL; insert=1; else /* 插入進(jìn)程提交時間最晚,則插入到隊(duì)尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() JCB *pr; pr=ready; if(p-link!=NULL) if(ready-ttimelink!
5、=NULL) pr=pr-link; pr-link=p; p-link=NULL; p=ready; ready=p-link; else ready=p; void input() /* 建立進(jìn)程控制塊函數(shù)*/ int i; clrscr(); /*清屏*/ printf(n input the number of process?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime nee
6、d to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w; p-link=NULL; sort(); /* 調(diào)用sort函數(shù)*/ void disp(JCB * pr) /*建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程*/ printf(n qname t state t ndtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check()
7、/* 建立進(jìn)程查看函數(shù) */ JCB* pr; printf(n * now the running process is:%s,p-name); /*顯示當(dāng)前運(yùn)行進(jìn)程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*顯示就緒隊(duì)列狀態(tài)*/ while(pr!=NULL)&(p-link!=NULL) if(pr-ttimelink; void destroy() /*建立進(jìn)程撤消函數(shù)(進(jìn)程運(yùn)行結(jié)束,撤消進(jìn)程)*/ num-; p-etime=ertime; p-zztime=ertime
8、-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pztime+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=NULL)ready=NULL; if(ready-link!=NULL) p=ready; ready
9、=p-link; elsep=ready; void running() /* 建立進(jìn)程就緒函數(shù)(進(jìn)程運(yùn)行時間到,置就緒狀態(tài))*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) destroy(); /* 調(diào)用destroy函數(shù)*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函數(shù)*/ int h=0; char
10、 ch; input(); p=ready; ready=p-link; while(num!=0)&(ready!=NULL) ch=getchar(); h+; printf(n The execute number:%d n,h); p-state=R; running(); printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround t
11、ime is %-3.1f,the average turnaround time with right is %-3.1fn,pztime,pqtime); ch=getchar(); 最短作業(yè)優(yōu)先(SJF):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define NULL 0 struct jcb /* 定義作業(yè)控制塊PCB */ char name10; char state; int ttime; int ntime; int rtime; int otime;
12、 int etime; float zztime; float dqtime; struct jcb* link; *ready=NULL,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb JCB; void sort() /* 建立對進(jìn)程進(jìn)行提交時間排列函數(shù)*/ JCB *first, *second; int insert=0; if(ready=NULL)|(p-ttime)ttime) /*提交時間最大者,插入隊(duì)首*/ p-link=ready; ready=p; els
13、e /* 進(jìn)程比較提交時間,插入適當(dāng)?shù)奈恢弥?/ first=ready; second=first-link; while(second!=NULL) if(p-ttime)ttime) /*若插入進(jìn)程比當(dāng)前提交時間早*/ /*插入到當(dāng)前進(jìn)程前面*/ p-link=second; first-link=p; second=NULL; insert=1; else /* 插入進(jìn)程提交時間最晚,則插入到隊(duì)尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() JCB *pr1,*pr2,*prx
14、,*pry; float x,y; prx=p; pry=prx-link; x=(srtime-p-otime)+(p-ntime); y=x/p-ntime; if(p-link!=NULL) while(pry!=NULL) if(yntime-pry-rtime) y=pry-ntime-pry-rtime;pr1=prx;pr2=pry; prx=prx-link;pry=prx-link; if(prx!=p&pr2-ttimelink=pr2-link;pr2-link=p;p=pr2;ready=p-link; else ready=p; void input() /* 建立進(jìn)
15、程控制塊函數(shù)*/ int i; clrscr(); /*清屏*/ printf(n input the number of process?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime need to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w;p-otime=0; p-link=NULL; sort(); /* 調(diào)
16、用sort函數(shù)*/ void disp(JCB * pr) /*建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程*/ printf(n qname t state t ndtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check() /* 建立進(jìn)程查看函數(shù) */ JCB* pr; p-otime=srtime; printf(n * now the running process is:%s,p-name);
17、 /*顯示當(dāng)前運(yùn)行進(jìn)程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*顯示就緒隊(duì)列狀態(tài)*/ while(pr!=NULL)&(p-link!=NULL) if(pr-ttimestate=w; disp(pr); pr=pr-link; void destroy() /*建立進(jìn)程撤消函數(shù)(進(jìn)程運(yùn)行結(jié)束,撤消進(jìn)程)*/ num-; p-etime=ertime; p-zztime=ertime-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pzti
18、me+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=NULL) ready=NULL;if(ready-link!=NULL) p=ready; ready=p-link; elsep=ready; void running() /* 建立進(jìn)程就緒函數(shù)
19、(進(jìn)程運(yùn)行時間到,置就緒狀態(tài))*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) destroy(); /* 調(diào)用destroy函數(shù)*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函數(shù)*/ int h=0; char ch; input(); p=ready; ready=p-link; while(num!=
20、0)&(ready!=NULL) ch=getchar(); h+; printf(n The execute number:%d n,h); p-state=R; running(); printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround time is %-3.1f,the average turnaround time with r
21、ight is %-3.1fn,pztime,pqtime); ch=getchar(); 響應(yīng)比高者優(yōu)先(HRN):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define NULL 0 struct jcb /* 定義作業(yè)控制塊PCB */ char name10; char state; int ttime; int ntime; int rtime; int otime; int etime; float zztime; float dqtime; struct
22、jcb* link; *ready=NULL,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb JCB; void sort() /* 建立對進(jìn)程進(jìn)行提交時間排列函數(shù)*/ JCB *first, *second; int insert=0; if(ready=NULL)|(p-ttime)ttime) /*提交時間最大者,插入隊(duì)首*/ p-link=ready; ready=p; else /* 進(jìn)程比較提交時間,插入適當(dāng)?shù)奈恢弥?/ first=ready; second=fi
23、rst-link; while(second!=NULL) if(p-ttime)ttime) /*若插入進(jìn)程比當(dāng)前提交時間早*/ /*插入到當(dāng)前進(jìn)程前面*/ p-link=second; first-link=p; second=NULL; insert=1; else /* 插入進(jìn)程提交時間最晚,則插入到隊(duì)尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() JCB *pr1,*pr2,*prx,*pry; int x; prx=p; pry=prx-link; x=(p-ntime)-
24、(p-rtime); if(p-link!=NULL) while(pry!=NULL) if(xpry-ntime-pry-rtime) x=pry-ntime-pry-rtime;pr1=prx;pr2=pry; prx=prx-link;pry=prx-link; if(prx!=p&pr2-ttimelink=pr2-link;pr2-link=p;p=pr2;ready=p-link; else ready=p;void input() /* 建立進(jìn)程控制塊函數(shù)*/ int i; clrscr(); /*清屏*/ printf(n input the number of proces
25、s?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime need to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w; p-link=NULL; sort(); /* 調(diào)用sort函數(shù)*/ void disp(JCB * pr) /*建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程*/ printf(n qname t state t n
26、dtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check() /* 建立進(jìn)程查看函數(shù) */ JCB* pr; printf(n * now the running process is:%s,p-name); /*顯示當(dāng)前運(yùn)行進(jìn)程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*顯示就緒
27、隊(duì)列狀態(tài)*/ while(pr!=NULL)&(p-link!=NULL) if(pr-ttimestate=w; disp(pr); pr=pr-link; void destroy() /*建立進(jìn)程撤消函數(shù)(進(jìn)程運(yùn)行結(jié)束,撤消進(jìn)程)*/ num-; p-etime=ertime; p-zztime=ertime-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pztime+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(
28、turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=NULL)ready=NULL; if(ready-link!=NULL) p=ready; ready=p-link; elsep=ready; void running() /* 建立進(jìn)程就緒函數(shù)(進(jìn)程運(yùn)行時間到,置就緒狀態(tài))*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) dest
29、roy(); /* 調(diào)用destroy函數(shù)*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函數(shù)*/ int h=0; char ch; input(); p=ready; ready=p-link; while(num!=0)&(ready!=NULL) ch=getchar(); h+; printf(n The execute number:%d n,h); p-state=R; running();
30、printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround time is %-3.1f,the average turnaround time with right is %-3.1fn,pztime,pqtime); ch=getchar(); (4) 每個函數(shù)的流程圖:先來先服務(wù)(FCFS):1. void sort()函數(shù):該函數(shù)用于對
31、進(jìn)程進(jìn)行提交時間排列。 insert=0開始 ready是否為空或者(p-ttime)是否小于(ready-ttime)? 是 否 first=ready;second=first-link進(jìn)程比較提交時間,插入適當(dāng)?shù)奈恢弥?p-link=ready;ready=p即提交時間最大者插入隊(duì)首second是否為空? 否 是(p-ttime)是否小于(second-ttime)insert是否為0 是 否 是 first=first-link second=second-link插入進(jìn)程提交時間最晚,則插入到隊(duì)尾first-link=pp-link=second;first-link=p secon
32、d=NULL;insert=1若插入進(jìn)程比當(dāng)前提交時間早,則插入到當(dāng)前進(jìn)程前面結(jié)束2. void pl()函數(shù)開始pr=readyp-link是否為空? 否 是ready-ttime是否小于等于srtimeready=p 是 否 pr-link是否為空是 pr-link=pp-link=NULL p=readyready=p-linkpr=pr-link結(jié)束3. void input()函數(shù):該函數(shù)用于建立進(jìn)程控制塊。開始清屏輸入進(jìn)程數(shù)目n=numi是否小于num 是 否p=getpch(JCB)結(jié)束輸入進(jìn)程名、提交時間和進(jìn)程所需運(yùn)行時間 p-rtime=0 p-state=w;p-link=
33、NULL調(diào)用sort函數(shù)4. void disp(JCB * pr)函數(shù):建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程。開始顯示當(dāng)前進(jìn)程(進(jìn)程名、進(jìn)程狀態(tài)、所需要的時間、運(yùn)行時間和提交時間)結(jié)束5. void check()函數(shù):該函數(shù)用于進(jìn)程查看。開始顯示當(dāng)前運(yùn)行進(jìn)程顯示就緒隊(duì)列狀態(tài)pr和p-link是否同時為空 否 是pr-ttime是否小于等于srtime 否 是 disp(pr)pr=pr-link結(jié)束開始6. void destroy()函數(shù):建立進(jìn)程撤消函數(shù)(進(jìn)程運(yùn)行結(jié)束,撤消進(jìn)程)。 num- p-etime=ertime p-zztime=ertime-p-ttimep-dqtime=p
34、-zztime/p-ntime pztime=pztime+p-zztime pqtime=pqtime+p-dqtime 進(jìn)程已經(jīng)完成輸出周轉(zhuǎn)時間和帶權(quán)周轉(zhuǎn)時間釋放pp-link是否為空? 是 否ready=NULLready-link是否為空?否 是p=ready p=readyready=p-link結(jié)束7. void running()函數(shù):建立進(jìn)程就緒函數(shù)(進(jìn)程運(yùn)行時間到,置就緒狀態(tài))。開始p-ttime是否小于等于srtime 是 否進(jìn)程未進(jìn)入內(nèi)存,等待下一時間(p-rtime)+ check() srtime+ ertime+調(diào)用pl()函數(shù)srtime+ertime+p-rti
35、me是否等于p-ntime?是 否p-state=w調(diào)用destroy函數(shù)結(jié)束8. 主函數(shù)開始 h=0 input() p=readyready=p-linknum是否為0且同時ready是否為空? 否 是pztime=pztime/npqtime=pqtime/n ch=getchar() h+ 進(jìn)程完成輸出平均周轉(zhuǎn)時間和平均帶權(quán)周轉(zhuǎn)時間p-state=R running()按任意鍵繼續(xù)ch=getchar()ch=getchar()結(jié)束最短作業(yè)優(yōu)先(SJF):1. void sort()函數(shù):該函數(shù)用于對進(jìn)程進(jìn)行提交時間排列。開始inser=0ready是否為空或者(p-ttime)是否小于(ready-ttime)? 是 否 first=ready;second=first-link進(jìn)程比較提交時間,插入適當(dāng)?shù)奈恢弥?p-link=ready;ready=p即提交時間最大者插入隊(duì)首second是否為空? 否 是(p-ttime)是否小于(second-ttime)insert是否為0 是 否 是 first=first-link second=second-link插入進(jìn)程提交時間最晚,則插入到隊(duì)尾first-link=pp-link=second;first-link=p second=NULL;insert=1若插入進(jìn)程比當(dāng)前提交時間早,則插入到當(dāng)前進(jìn)程前面結(jié)束2.
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 趣味運(yùn)動會開幕詞(15篇)
- 講文明國旗下講話稿(3篇)
- 少兒聲樂課課程設(shè)計案例
- 統(tǒng)編版語文專題02常見的關(guān)聯(lián)詞及其作用-2024年四升五暑期閱讀精準(zhǔn)突破(含答案)
- 教師參加黨代會的發(fā)言稿
- 2024版2024離婚協(xié)議書談話筆錄五篇范文
- 2024年暑假五升六語文自學(xué)課day7解鎖文言文閱讀的實(shí)詞理解題型(學(xué)生版+家長版)
- 內(nèi)墻膩?zhàn)庸こ淌┕趧?wù)合同
- c語言課程設(shè)計餐館
- 2024年春季開學(xué)“安全教育周”活動方案
- 幼兒園公開課:大班語言《相反國》課件(優(yōu)化版)
- 小學(xué)六年級數(shù)學(xué)計算題100道(含答案)
- 土建工程常見質(zhì)量缺陷與處理措施方案
- lxh汽輪機(jī)TSIe
- 小學(xué)三年級上冊品德道德與法治-《走近我們的老師》(23張)ppt課件
- 最新 育嬰師實(shí)操技能題
- 勞務(wù)培訓(xùn)計劃
- 項(xiàng)目部管理人員分工
- (完整版)鋼板焊接施工方案
- (完整版)生產(chǎn)異常問題反饋流程
- 航車安全操作規(guī)程
評論
0/150
提交評論