實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)_第1頁(yè)
實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)_第2頁(yè)
實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)_第3頁(yè)
實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)_第4頁(yè)
實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)_第5頁(yè)
已閱讀5頁(yè),還剩17頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)驗(yàn)二作業(yè)調(diào)度實(shí)驗(yàn)一. 實(shí)驗(yàn)?zāi)康囊?#160; 用高級(jí)語(yǔ)言編寫(xiě)和調(diào)試一個(gè)或多個(gè)作業(yè)調(diào)度的模擬程序,以加深對(duì)作業(yè)調(diào)度算法的理解。  二. 實(shí)驗(yàn)要求  1、編寫(xiě)并調(diào)試一個(gè)單道處理系統(tǒng)的作業(yè)等待模擬程序。 作業(yè)等待算法:分別采用先來(lái)先服務(wù)(fcfs),最短作業(yè)優(yōu)先(sjf)、響應(yīng)比高者優(yōu)先(hrn)的調(diào)度算法。 對(duì)每種調(diào)度算法都要求打印每個(gè)作業(yè)開(kāi)始運(yùn)行時(shí)刻、完成時(shí)刻、周轉(zhuǎn)時(shí)間、帶權(quán)周轉(zhuǎn)時(shí)間,以及這組作業(yè)的平均周轉(zhuǎn)時(shí)間及帶權(quán)平均周轉(zhuǎn)時(shí)間,以比較各種算法的優(yōu)缺點(diǎn)。 2、編寫(xiě)并調(diào)度一個(gè)多道程序系統(tǒng)的作業(yè)調(diào)度模擬程序。 作業(yè)調(diào)度算法:采用基于先來(lái)先服務(wù)的調(diào)度算法??梢詤⒖颊n本

2、中的方法進(jìn)行設(shè)計(jì)。 對(duì)于多道程序系統(tǒng),要假定系統(tǒng)中具有的各種資源及數(shù)量、調(diào)度作業(yè)時(shí)必須考慮到每個(gè)作業(yè)的資源要求。3、編寫(xiě)并調(diào)試一個(gè)多道程序系統(tǒng)的作業(yè)調(diào)度模擬程序。 作業(yè)調(diào)度算法:采用基于優(yōu)先級(jí)的作業(yè)調(diào)度。 三、實(shí)驗(yàn)過(guò)程1.單道處理系統(tǒng)的作業(yè)等待模擬程序(分別采用先來(lái)先服務(wù)(fcfs),最短作業(yè)優(yōu)先(sjf)、響應(yīng)比高者優(yōu)先(hrn)的調(diào)度算法。 )實(shí)習(xí)代碼:#include "stdio.h"#include "stdlib.h"#define getjcb(type)(type*)malloc(sizeof(type)#define null 0str

3、uct jcbchar name10;int htime;int ntime;char state;struct jcb *link; *ready=null,*p;typedef struct jcb jcb;int input()int num,i,t=0;void sort();printf("n請(qǐng)輸入作業(yè)個(gè)數(shù):");scanf("%d",&num);for(i=1;i<=num;i+)printf("n作業(yè) %d",i);p=(jcb*)malloc(sizeof(jcb);printf("n作業(yè)名:&

4、quot;);scanf("%s",p->name);printf("n作業(yè)運(yùn)行時(shí)間:");scanf("%d",&p->ntime);p->htime=t; p->state='w' p->link=null;sort();t+;return t;void sort()jcb *flag;if(ready=null)ready=p;elseflag=ready;while(flag->link!=null)flag=flag->link;flag->link=p

5、;void show()jcb *pr;printf("n*正在運(yùn)行的作業(yè)是 :%s ",p->name);printf("nnamethtimetntimetstaten");printf("%st",p->name);printf("%dt",p->htime);printf("%dt",p->ntime);printf("%ct",p->state);printf("nn*就緒隊(duì)列");for(pr=ready;pr!=

6、null;pr=pr->link)printf("nnamethtimetntimetstaten");printf("%st",pr->name);printf("%dt",pr->htime);printf("%dt",pr->ntime);printf("%ct",pr->state);void running()printf("n作業(yè) %s已經(jīng)完成n",p->name);free(p);main()char c;int t=0; i

7、nt tb,tc,ti,wi;int tis=0,wis=0,i=0;t=input();while(ready!=null)c=getchar();+i;p=ready;ready=p->link;p->link=null;p->state='r'tb=t;show();/printf("npress any key to continue.");c=getchar();running();tc=tb+p->ntime;/完成時(shí)間ti=tc-p->htime;/周轉(zhuǎn)時(shí)間tis+=ti;wi=ti/p->ntime;/平均

8、帶權(quán)周轉(zhuǎn)wis+=wi;printf("n作業(yè) %d 開(kāi)始: n", t);printf("n作業(yè)%d 完成:n",t);printf("n周轉(zhuǎn)時(shí)間:%dn",ti);printf("n帶權(quán)周轉(zhuǎn)時(shí)間: %dn",wi);t=t+p->ntime;/printf("npress any key to continue.");c=getchar();printf("n*所有作業(yè)都已經(jīng)完成");printf("n總周轉(zhuǎn)時(shí)間:%dn",tis/i);prin

9、tf("n總帶權(quán)周轉(zhuǎn)時(shí)間:%dn",wis/i);/printf("npress any key to continue.");c=getchar();運(yùn)行結(jié)果: 2. 多道程序系統(tǒng)的作業(yè)調(diào)度模擬程序(采用基于先來(lái)先服務(wù)的調(diào)度算法)實(shí)習(xí)代碼:#include <stdio.h>#include <stdlib.h> #define getjch(type) (type*)malloc(sizeof(type) #define n 10struct jcb /* 定義作業(yè)控制塊pcb */ char name10; float ne

10、edtime; /*運(yùn)行時(shí)間*/float arrivetime;/*提交時(shí)刻*/float storagen;/*系統(tǒng)資源*/struct jcb* link; *ready=null,*pb=null,*p; typedef struct jcb jcb; float tc,ti,wi,t=0;/*完成時(shí)刻,周轉(zhuǎn)時(shí)間,帶權(quán)周轉(zhuǎn)時(shí)間,時(shí)間量*/float tisum=0,wisum=0;/*平均周轉(zhuǎn)時(shí)間,帶權(quán)a平均周轉(zhuǎn)時(shí)間*/float sourcen;int n;void input(); /*輸入作業(yè)信息*/int space(); /* 返回就緒隊(duì)列中作業(yè)的數(shù)目*/void fcfs(

11、); /*先來(lái)先服務(wù)算法*/void disp(jcb *pr); /* 顯示相應(yīng)的作業(yè)*/void running(); /*運(yùn)行作業(yè)組*/void destroy(); /* 撤銷(xiāo)作業(yè)*/void input() /* 建立作業(yè)控制塊函數(shù)*/ int i,k,num; printf("請(qǐng)輸入所擁有的資源種類(lèi):");scanf("%d",&n);printf("輸入系統(tǒng)所擁有資源數(shù):n");for(i=0;i<n;i+)printf("資源%d:",i);scanf("%f",&

12、amp;sourcei); printf("n 輸入作業(yè)數(shù)量:");scanf("%d",&num); for(i=0;i<num;i+) printf("n 作業(yè)號(hào)%d:n",i);p=getjch(jcb); printf("輸入作業(yè)名:");scanf("%s",p->name); printf("輸入提交時(shí)間:");scanf("%f",&p->arrivetime);printf("輸入運(yùn)行時(shí)間:&qu

13、ot;);scanf("%f",&p->needtime); printf("輸入所需資源數(shù):n");for(k=0;k<n;k+)printf("資源%d:",i);scanf("%f",&p->storagek); printf("n"); p->link=null; fcfs(); int space() int l=0; jcb* pr=ready; while(pr!=null) l+; pr=pr->link; return(l); vo

14、id disp(jcb * pr) /*建立作業(yè)顯示函數(shù),用于顯示當(dāng)前作業(yè)*/ int i;printf("n%6st%6st%6st","作業(yè)名","運(yùn)行時(shí)間","提交時(shí)刻");for(i=0;i<n;i+)printf("資源%dt",i);printf("n%6st%6.2ftt%6.2ft",pr->name,pr->needtime,pr->arrivetime);for(i=0;i<n;i+)printf("t%6.2f&q

15、uot;,pr->storagei);printf("n"); void destroy() /*建立作業(yè)撤消函數(shù)(作業(yè)運(yùn)行結(jié)束,撤消作業(yè))*/ free(p); void check()jcb *first,*fir,*p;int flag=0,i,test=0;first=pb;while(first&&(t>=first->arrivetime)&&(flag=0)for(i=0;i<n;i+)if(sourcei>=first->storagei)sourcei=sourcei-first->

16、storagei;elsetest=1;if(test=0)p=first;first=first->link;p->link=null;if(ready=null)ready=p;elsefir=ready;while(fir->link!=null)fir=fir->link;fir->link=p;elseflag=1;pb=first;void fcfs()jcb *first,*second;int ins=0;if(pb=null)|(p->arrivetime<pb->arrivetime)p->link=pb;pb=p;el

17、sefirst=pb;second=first->link;while(second!=null)if(p->arrivetime<second->arrivetime)p->link=second;second=null;first->link=p;ins=1;else first=first->link; second=second->link;if(ins=0)first->link=p;void running()jcb *pr;int i;printf("正在運(yùn)行的作業(yè)是:%sn",p->name);di

18、sp(p);if(ready!=null)printf("就緒隊(duì)列如下:n");pr=ready;while(pr!=null)disp(pr);pr=pr->link;elseprintf("就緒隊(duì)列為空隊(duì)列!n");if(pb!=null)printf("后備隊(duì)列如下:n");pr=pb;while(pr!=null)disp(pr);pr=pr->link;elseprintf("后備隊(duì)列為空隊(duì)列!n");printf("作業(yè)%s的開(kāi)始運(yùn)行時(shí)刻t:%4.2fn",p->n

19、ame,t);tc=t+p->needtime;t=tc;ti=tc-p->arrivetime;wi=ti/(p->needtime);for(i=0;i<n;i+)sourcei=sourcei+p->storagei;printf("完成時(shí)刻tc:%4.2fn",tc);printf("周轉(zhuǎn)時(shí)間ti:%4.2fn",ti);printf("帶權(quán)周轉(zhuǎn)時(shí)間wi:%4.2fn",wi);tisum+=ti;wisum+=wi;destroy();main() /主函數(shù)int len; char ch;in

20、put(); t=pb->arrivetime;check();len=space(); while(len!=0)&&(ready!=null) system("pause");p=ready; ready=p->link; p->link=null; running();if(pb!=null)if(ready=null)if(t<pb->arrivetime)t=pb->arrivetime;check();len=space(); printf("n該作業(yè)組的平均周轉(zhuǎn)時(shí)間:%4.2fn",tis

21、um /len); printf("該作業(yè)組的帶權(quán)平均周轉(zhuǎn)時(shí)間:%4.2fn",wisum/len);ch=getchar(); 運(yùn)行結(jié)果:3.多道程序系統(tǒng)的作業(yè)調(diào)度模擬程序。 (采用基于優(yōu)先級(jí)的作業(yè)調(diào)度) 實(shí)習(xí)代碼:#include <stdio.h>#include <stdlib.h> #define getjch(type) (type*)malloc(sizeof(type) #define n 10struct jcb /* 定義作業(yè)控制塊pcb */ char name10; float needtime; /*運(yùn)行時(shí)間*/float

22、arrivetime;/*提交時(shí)刻*/float storagen;/*系統(tǒng)資源*/struct jcb* link; *ready=null,*pb=null,*p; typedef struct jcb jcb; float tc,ti,wi,t=0;/*完成時(shí)刻,周轉(zhuǎn)時(shí)間,帶權(quán)周轉(zhuǎn)時(shí)間,時(shí)間量*/float tisum=0,wisum=0;/*平均周轉(zhuǎn)時(shí)間,帶權(quán)a平均周轉(zhuǎn)時(shí)間*/float sourcen;int n;void input(); /*輸入作業(yè)信息*/int space(); /* 返回就緒隊(duì)列中作業(yè)的數(shù)目*/void fcfs(); /*先來(lái)先服務(wù)算法*/void dis

23、p(jcb *pr); /* 顯示相應(yīng)的作業(yè)*/void running(); /*運(yùn)行作業(yè)組*/void destroy(); /* 撤銷(xiāo)作業(yè)*/void input() /* 建立作業(yè)控制塊函數(shù)*/ int i,k,num; printf("請(qǐng)輸入所擁有的資源種類(lèi):");scanf("%d",&n);printf("輸入系統(tǒng)所擁有資源數(shù):n");for(i=0;i<n;i+)printf("資源%d:",i);scanf("%f",&sourcei); printf(&

24、quot;n 輸入作業(yè)數(shù)量:");scanf("%d",&num); for(i=0;i<num;i+) printf("n 作業(yè)號(hào)%d:n",i);p=getjch(jcb); printf("輸入作業(yè)名:");scanf("%s",p->name); printf("輸入提交時(shí)間:");scanf("%f",&p->arrivetime);printf("輸入運(yùn)行時(shí)間:");scanf("%f&qu

25、ot;,&p->needtime); printf("輸入所需資源數(shù):n");for(k=0;k<n;k+)printf("資源%d:",i);scanf("%f",&p->storagek); printf("n"); p->link=null; fcfs(); int space() int l=0; jcb* pr=ready; while(pr!=null) l+; pr=pr->link; return(l); void disp(jcb * pr) /*建立

26、作業(yè)顯示函數(shù),用于顯示當(dāng)前作業(yè)*/ int i;printf("n%6st%6st%6st","作業(yè)名","運(yùn)行時(shí)間","提交時(shí)刻");for(i=0;i<n;i+)printf("資源%dt",i);printf("n%6st%6.2ftt%6.2ft",pr->name,pr->needtime,pr->arrivetime);for(i=0;i<n;i+)printf("t%6.2f",pr->storagei);

27、printf("n"); void destroy() /*建立作業(yè)撤消函數(shù)(作業(yè)運(yùn)行結(jié)束,撤消作業(yè))*/ free(p); void check()jcb *first,*fir,*p;int flag=0,i,test=0;first=pb;while(first&&(t>=first->arrivetime)&&(flag=0)for(i=0;i<n;i+)if(sourcei>=first->storagei)sourcei=sourcei-first->storagei;elsetest=1;if

28、(test=0)p=first;first=first->link;p->link=null;if(ready=null)ready=p;elsefir=ready;while(fir->link!=null)fir=fir->link;fir->link=p;elseflag=1;pb=first;void fcfs()jcb *first,*second;int ins=0;if(pb=null)|(p->arrivetime<pb->arrivetime)p->link=pb;pb=p;elsefirst=pb;second=first->link;while(second!=null)if(p->arrivetime<second->arrivetime)p->link=second;second=null;first->link=p;ins=1;else first=first->link; second=second->link;if(ins=0)first->link=p;void running()jcb *pr;int i;printf("正在運(yùn)行的作業(yè)是:%sn",p->name);disp(p);if(ready!=

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論