OS_時(shí)間片輪轉(zhuǎn)調(diào)度算法_第1頁
OS_時(shí)間片輪轉(zhuǎn)調(diào)度算法_第2頁
OS_時(shí)間片輪轉(zhuǎn)調(diào)度算法_第3頁
OS_時(shí)間片輪轉(zhuǎn)調(diào)度算法_第4頁
OS_時(shí)間片輪轉(zhuǎn)調(diào)度算法_第5頁
免費(fèi)預(yù)覽已結(jié)束,剩余9頁可下載查看

下載本文檔

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

文檔簡介

1、時(shí)間片輪轉(zhuǎn)調(diào)度算法實(shí)驗(yàn)?zāi)康模?1)學(xué)習(xí)時(shí)間片輪轉(zhuǎn)調(diào)度算法。2)學(xué)習(xí)C+程序設(shè)計(jì)的方法。二實(shí)驗(yàn)環(huán)境:1) 一臺(tái)運(yùn)行 Windows2000Professional操作系統(tǒng)計(jì)算機(jī)。2)計(jì)算機(jī)中需要安裝VisualC+6.0企業(yè)版。三實(shí)驗(yàn)內(nèi)容:本實(shí)驗(yàn)主要是實(shí)現(xiàn)時(shí)間片輪轉(zhuǎn)調(diào)度算法。1)進(jìn)入VisualC+啲窗口,新建一個(gè)C+啲文件,命名為01.Cpp.2)在源程 序編輯窗口輸入如下的源程序:#include<iostream>#include<string>#include<time.h>usingnamespacestd;intn;classPCBpublic:i

2、ntpri;/ 進(jìn)程優(yōu)先數(shù)intruntime;/進(jìn)程運(yùn)行CPU時(shí)間intpieceOftime;/ 輪轉(zhuǎn)時(shí)間片stringprocname;/ 進(jìn)程名stringstate;/ 進(jìn)程狀態(tài)intneedOftime;/ 還需要時(shí)間intCounter;PCB*next;PCB*run=NULL;PCB*ready=NULL;PCB*finish=NULL;PCB*tial=ready;voidDtime(intt);voidPrinft(inta)if(a=1)coutvv"進(jìn)程名稱"vv"t"vv"優(yōu)先數(shù)"vv"t&quo

3、t;vv"還需要時(shí)間"vv"t"vv"已運(yùn)行 時(shí)間 "<<"t"<<" 狀態(tài) :"<<endl;elsecoutvv"進(jìn)程名稱"<<"t"<<"已運(yùn)行時(shí)間"<<"t"<<"還需要時(shí)間"<<"t"<<"計(jì) 數(shù)器"vv"t"vv&quo

4、t;時(shí)間片"vv"t"vv"狀態(tài)"vvendl;voidPrinft(intb,PCB*p)if(b=1)cout<<p->procname<<"tt"<<p->pri<<"t"<<p->needOftime<<"tt"<<p->r untime<<"tt"<<p->state<<endl;elsecout<&l

5、t;p->procname<<"tt"<<p->runtime<<"tt"<<p->needOftime<<"tt"<<p->Counter<<"t"<<p->pieceOftime<<"t"<<p->state<<endl;voiddisplay(intc)PCB*p;if(run!=NULL)/* 如果運(yùn)行指針不空 */Pri

6、nft(c,run);/* 輸出當(dāng)前正在運(yùn)行的 PCB*/Dtime(2);p=ready;/* 輸出就緒隊(duì)列 PCB*/while(p!=NULL)Prinft(c,p);p=p->next;/Dtime(2);p=finish;/* 輸出完成隊(duì)列的 PCB*/while(p!=NULL)Prinft(c,p);p=p->next;voidinsert(PCB*p)/ 插入就緒隊(duì)列按 Pri 大小PCB*S1,*S2;if(ready=NULL)p->next=NULL;ready=p;elseS1=ready;S2=S1;while(S1!=NULL)14 / 14if(

7、S1->pri>=p->pri)S2=S1;S1=S1->next;elsebreak;if(S2->pri>=p->pri)S2->next=p;p->next=S1;elsep->next=ready;ready=p;boolCTProcessOfPri()PCB*Node;coutvv"輸入創(chuàng)建進(jìn)程的數(shù)目:"vvendl;cin >>n;for(intj=0;j<n;j+)Node=newPCB;if(Node=NULL)returnfalse;elsecoutvv"輸入進(jìn)程的名稱

8、,進(jìn)程需CPU時(shí)間:"vvendl;cin>>Node->procname>>Node->needOftime;Node->runtime=0;Node->state二"就緒"Node->pri=Node->needOftime;coutvv"進(jìn)程"vvNode->procnameW創(chuàng)建完畢!"vvendl;insert(Node);returntrue;voidpriority(inti)run=ready;ready=ready->next;run->s

9、tate二"運(yùn)行”;Prinft(i);while(run!=NULL)/* 當(dāng)運(yùn)行隊(duì)列不空時(shí),有進(jìn)程正在運(yùn)行 */run->runtime=run->runtime+1;run->needOftime=run->needOftime-1;run->pri=run->pri-1;/* 每運(yùn)行一次優(yōu)先數(shù)降低 1個(gè)單位 */if(run->needOftime=0)/* 如所需時(shí)間為 0 將其插入完成隊(duì)列 */run->state二"完成"run->next=finish;finish=run;run二NULL;/

10、*運(yùn)行隊(duì)列頭指針為空*/if(ready!二NULL)/*如就緒隊(duì)列不空*/run=ready;run->state二"運(yùn)行”;ready=ready->next;elseif(ready!=NULL)&&(run->pri<ready->pri)run->state二"就緒"insert(run);run=ready;run->state二"運(yùn)行"ready=ready->next;display(i);/*輸出進(jìn)程PCB信息*/voidqueue(PCB*p)if(ready=

11、NULL)p->next=NULL;ready=p;tial=p;elsetial->next=p;tial=p;p->next=NULL;boolCTProcessOfRuntime()PCB*Node;intm;coutvv"輸入創(chuàng)建進(jìn)程的數(shù)目:"vvendl;cin >>n;coutvv"輸入時(shí)間片:"vvendl;cin>>m;for(intj=0;jvn;j+)Node=newPCB;if(Node=NULL)returnfalse;elsecoutvv"輸入進(jìn)程的名稱,進(jìn)程需CPU時(shí)間:&q

12、uot;<<endl;cin>>Node->procname>>Node->needOftime;Node->runtime=0;Node->state二"就緒"Node->Counter=0;Node->pieceOftime=m;coutvv"進(jìn)程"<<Node->procname<<'創(chuàng)建完畢!"vvendl;queue(Node);returntrue;voidRuntime(intc)run=ready;ready=ready

13、->next;run->state二"運(yùn)行"Prinft(c);while(run!=NULL)run->runtime=run->runtime+1;run->needOftime=run->needOftime-1;run->Counter=run->Counter+1;if(run->needOftime=0)run->state二"完成”;run->next=finish;finish=run;run=NULL;if(ready!=NULL)run=ready;ready=ready->

14、;next;elseif(run->Counter=run->pieceOftime)run->Counter=0;run->state二"就緒”;queue(run);run=NULL;if(ready!=NULL)run=ready;run->state二"運(yùn)行"ready=ready->next;display(c);intmain()inti;cout<<"*"<<endl;cout<<"*1 優(yōu)先數(shù)調(diào)度算法 2 循環(huán)時(shí)間片輪轉(zhuǎn)算法 *"<<endl;cout<<"*0 退出 *"<<endl;cin>>i;switch(i)case1:CTProcessOfPri();priority(i);break;cas

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論