操作系統(tǒng)實(shí)驗(yàn)-動(dòng)態(tài)優(yōu)先級(jí)進(jìn)程調(diào)度實(shí)驗(yàn)報(bào)告_第1頁(yè)
操作系統(tǒng)實(shí)驗(yàn)-動(dòng)態(tài)優(yōu)先級(jí)進(jìn)程調(diào)度實(shí)驗(yàn)報(bào)告_第2頁(yè)
操作系統(tǒng)實(shí)驗(yàn)-動(dòng)態(tài)優(yōu)先級(jí)進(jìn)程調(diào)度實(shí)驗(yàn)報(bào)告_第3頁(yè)
操作系統(tǒng)實(shí)驗(yàn)-動(dòng)態(tài)優(yōu)先級(jí)進(jìn)程調(diào)度實(shí)驗(yàn)報(bào)告_第4頁(yè)
操作系統(tǒng)實(shí)驗(yàn)-動(dòng)態(tài)優(yōu)先級(jí)進(jìn)程調(diào)度實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、1.實(shí)驗(yàn)名稱:動(dòng)態(tài)優(yōu)先權(quán)調(diào)度過(guò)程中就緒隊(duì)列的模擬2.實(shí)驗(yàn)要求:采用動(dòng)態(tài)優(yōu)先權(quán)的進(jìn)程調(diào)度算法,用C語(yǔ)言編程模擬調(diào)度過(guò)程中每個(gè)時(shí)間片內(nèi)的就緒隊(duì)列。3.實(shí)驗(yàn)內(nèi)容:(1)每個(gè)進(jìn)程控制塊PCB用結(jié)構(gòu)描述,包括以下字段:*進(jìn)程標(biāo)識(shí)符id*進(jìn)程優(yōu)先數(shù)priority,并規(guī)定優(yōu)先數(shù)越大的進(jìn)程,其優(yōu)先權(quán)越高。*進(jìn)程已占用的CPU時(shí)間cputime*進(jìn)程還需占用的CPU時(shí)間alltime,當(dāng)進(jìn)程運(yùn)行完畢時(shí),aiitime變?yōu)?*進(jìn)程的阻塞時(shí)間startblock,當(dāng)進(jìn)程再運(yùn)行startblock個(gè)時(shí)間片后,進(jìn)程將進(jìn)入阻塞狀態(tài)*進(jìn)程被阻塞的時(shí)間blocktime,已阻塞的進(jìn)程再等待blocktime個(gè)時(shí)間片后,將轉(zhuǎn)

2、換成就緒狀態(tài)*進(jìn)程狀態(tài)state*隊(duì)列指針next,將PCB排成隊(duì)列。2)調(diào)度前,系統(tǒng)中有五個(gè)進(jìn)程,它們的初始狀態(tài)如下:ID01234PRIORITY93830290CPUTIME00000ALLTIME33634STARTBLOCK2-1-1-1-1BLOCKTIME30000STATEREADYREADYREADYREADYREADY3)進(jìn)程在就緒隊(duì)列呆一個(gè)時(shí)間片,優(yōu)先數(shù)增加1。4)進(jìn)程每運(yùn)行一個(gè)時(shí)間片,優(yōu)先數(shù)減3。5)按下面格式顯示每個(gè)時(shí)間片內(nèi)就緒隊(duì)列的情況:READY_QUEUE:-id1-id24.任務(wù)分析進(jìn)程控制塊用結(jié)構(gòu)體來(lái)表示,包含它的各項(xiàng)屬性。建立兩個(gè)隊(duì)列:一個(gè)就緒隊(duì)列,一個(gè)阻

3、塞隊(duì)列。創(chuàng)建一個(gè)進(jìn)程控制塊表示當(dāng)前正在運(yùn)行的進(jìn)程。程序開(kāi)始運(yùn)行時(shí),所有進(jìn)程都在就緒隊(duì)列中。當(dāng)startblock減少到0時(shí),進(jìn)程進(jìn)入阻塞隊(duì)列。在阻塞隊(duì)列中的進(jìn)程,當(dāng)blocktime減少到0時(shí),轉(zhuǎn)入就緒隊(duì)列。在就緒隊(duì)列中的進(jìn)程,如果優(yōu)先級(jí)比當(dāng)前正在執(zhí)行的進(jìn)程高,就可以取代當(dāng)前進(jìn)程獲取時(shí)間片。當(dāng)前進(jìn)程如果運(yùn)行完畢,就緒隊(duì)列中優(yōu)先級(jí)最高的進(jìn)程就可以成為新當(dāng)前進(jìn)程。5.程序流程圖程序清單#includeiostream#includestringusingnamespacestd;#defineLEN5typedefenumSTATEREADYBLOCKENDSTATE;/定義進(jìn)程控制塊typede

4、fstructPCBintid;intpriority;intcputime;intalltime;intstartblock;intblocktime;STATEstate;PCB;/定義隊(duì)列typedefstructqueueintsize;PCB*dataLEN;Queue;PCBpsLEN;PCB*cp;/進(jìn)程最大數(shù)量/進(jìn)程狀態(tài)/就緒/阻塞/完成/進(jìn)程標(biāo)識(shí)符/進(jìn)程優(yōu)先級(jí)/已占用的CPU時(shí)間/還需占用的CPU時(shí)間/阻塞時(shí)間/被阻塞時(shí)間/進(jìn)程狀態(tài)/隊(duì)列中進(jìn)程的數(shù)量/進(jìn)程的指針/進(jìn)程數(shù)組/當(dāng)前正在運(yùn)行的進(jìn)程QueuerQueue,bQueue;/就緒隊(duì)列和阻塞隊(duì)列/就緒隊(duì)列按優(yōu)先級(jí)降序排序(

5、使用了冒泡排序法)voidrQueueSort()PCB*temp;for(inti=0;irQueue.size-1;i+)for(intj=0;jrQueue.size-1-i;j+)if(rQueue.dataj-priorityrQueue.dataj+1-priority)temp=rQueue.dataj;rQueue.dataj=rQueue.dataj+1;rQueue.dataj+1=temp;/初始化voidinit()/給進(jìn)程賦值for(inti=0;iLEN;i+)psi.id=i;psi.state=READY;psi.cputime=0;psi.alltime=3;

6、psi.blocktime=0;psi.startblock=T;ps0.priority=9;ps1.priority=38;ps2.priority=30;ps3.priority=29;ps4.priority=0;ps2.alltime=6;ps4.alltime=4;ps0.startblock=2;ps0.blocktime=3;cp=NULL;/當(dāng)前進(jìn)程賦空bQueue.size=0;/阻塞隊(duì)列沒(méi)有進(jìn)程for(inti=0;iLEN;i+)bQueue.datai=NULL;rQueue.datai=rQueue.size=5;/所有進(jìn)程全部進(jìn)入就緒隊(duì)列rQueueSort();

7、/對(duì)就緒隊(duì)列排序/打印voidprint()coutid;coutnREADY_QUEUE:;for(inti=0;irQueue.size;i+)cout-rQueue.datai-id;coutnBLOCK_QUEUE:;for(inti=0;ibQueue.size;i+)cout-bQueue.datai-id;coutnendl;coutIDtt;for(inti=0;iLEN;i+)coutpsi.idt;coutnPRI0RITYt;for(inti=0;iLEN;i+)coutpsi.priorityt;coutnCPUTIMEtt;for(inti=0;iLEN;i+)cou

8、tpsi.cputimet;coutnALLTIMEtt;for(inti=0;iLEN;i+)coutpsi.alltimet;coutnSTARTBLOCKt;for(inti=0;iLEN;i+)coutpsi.startblockt;coutnBLOCKTIMEt;for(inti=0;iLEN;i+)coutpsi.blocktimet;coutnSTATEtt;for(inti=0;iLEN;i+)if(psi.state=READY)coutREADYt;elseif(psi.state=BLOCK)coutBLOCKt;elseif(psi.state=END)coutEND0

9、)temp=q-data0;/取出隊(duì)首進(jìn)程for(inti=0;isize一;returntemp;/返回隊(duì)首進(jìn)程returnNULL;/入隊(duì)voidpush(Queue*q,PCB*p)if(q-sizedataq-size=p;/將入隊(duì)的進(jìn)程放在隊(duì)尾q_size+;return;/運(yùn)行進(jìn)程voidrun()if(rQueue.size0|bQueue.size0)if(cp=NULL)/程序一開(kāi)始運(yùn)行時(shí),從就緒隊(duì)列取出首進(jìn)程cp=pop(&rQueue);/當(dāng)前進(jìn)程沒(méi)有結(jié)束,但優(yōu)先級(jí)比就緒隊(duì)列首進(jìn)程低if(cp_alltime0&cp_prioritystate=END;cp=pop(&r

10、Queue);/如果當(dāng)前進(jìn)程運(yùn)行結(jié)束/改變進(jìn)程狀態(tài)/從就緒隊(duì)列取出新的當(dāng)前進(jìn)程cppriority-=3;/修改當(dāng)前進(jìn)程的優(yōu)先級(jí)/將當(dāng)前進(jìn)程放入就緒隊(duì)列/就緒隊(duì)列隊(duì)首進(jìn)程成為當(dāng)前進(jìn)程/startblock為0,標(biāo)志著當(dāng)前進(jìn)程要進(jìn)入阻塞狀態(tài)if(cpstartblock=0&cpblocktime0)cpstate=BLOCK;push(&bQueue,cp);cp=pop(&rQueue);elseif(cpstartblock0)cpstartblock一;/修改當(dāng)前進(jìn)程的狀態(tài)/將當(dāng)前進(jìn)程加入阻塞隊(duì)列/從就緒隊(duì)列取出新的當(dāng)前進(jìn)程/當(dāng)前進(jìn)程的startblock為正數(shù)時(shí)/運(yùn)行一次減一個(gè)時(shí)間片c

11、pcputime+;/當(dāng)前進(jìn)程占用CPU時(shí)間片+1if(cpalltime0)/當(dāng)前進(jìn)程還需運(yùn)行的時(shí)間片-1cpalltime;if(cpalltime=0)/減到0時(shí),修改進(jìn)程狀態(tài)cpstate=END;/每運(yùn)行一個(gè)時(shí)間片/就緒隊(duì)列中的進(jìn)程優(yōu)先級(jí)+1/每運(yùn)行一個(gè)時(shí)間片/阻塞隊(duì)列中的進(jìn)程blocktime-1for(inti=0;irQueue.size;i+)rQueue.datai-priority+;for(inti=0;i0)bQueue.datai-blocktime-;/當(dāng)阻塞隊(duì)列隊(duì)首進(jìn)程blocktime為0時(shí)if(bQueue.size0&bQueue.data0-blockt

12、ime=0)bQueue.data0-state=READY;/修改進(jìn)程狀態(tài)push(&rQueue,pop(&bQueue);/將阻塞隊(duì)列首進(jìn)程取出,放入就緒隊(duì)列/每運(yùn)行一個(gè)時(shí)間片,就緒隊(duì)列排一次序rQueueSort();/主函數(shù)intmain()init();/初始化print();/打印進(jìn)程信息while(1)_sleep(1000);if(rQueue.size=0&bQueue.size=0)/當(dāng)兩個(gè)隊(duì)列都為空時(shí),結(jié)束程序cp-state=END;break;run();/運(yùn)行進(jìn)程print();/打印進(jìn)程信息return0;實(shí)驗(yàn)過(guò)程記錄IGPROG:1QLiEUE:-2-3-0-

13、4亂EUE:m匸:WINDaWSsystem32cmd.exeNGPROG:r_QUEUE:-l-.2-3-0-4x33003TQlx630o程序開(kāi)始執(zhí)行,當(dāng)前進(jìn)程是優(yōu)先級(jí)最高的1號(hào)進(jìn)程,1號(hào)進(jìn)程的優(yōu)先級(jí)減3、cputime+、0go323READY13803-L0READYDYEAoR2903-10READY-10READY0100323READY13512-10READY4L04-10READYalltime-。在就緒隊(duì)列中的進(jìn)程優(yōu)先級(jí)全部加1。CWINDOWSy5tem32crrdjExeXRUNNINGPROG:1READYQLELE:-2-3-0-4BLOCKQLELE:D0L234

14、PRIORITYL22933323CPUTIME03000rLLTIME30634STARTBLOCK2-1-1-1-1BLOCKTIME30000STATEREADYENDREADYREADYREADYRUNNING-PROG:2READY_QVELE:-3-0-4BLOd_QUEUE:D0L3PRIORITY13293033fcPUTIME030ALLTIME303STARTBLQCK2-1-1-1-1BLOCKTIME30000pATEREADYENDREADYREADYREADY執(zhí)行幾次之后,1號(hào)進(jìn)程執(zhí)行完畢而且優(yōu)先級(jí)也不是最高的了,所以優(yōu)先級(jí)為33的2號(hào)進(jìn)程成為當(dāng)前進(jìn)程,開(kāi)始執(zhí)行。Q

15、ICAWINDOWS5ystem32cmdjeKe-XRUNNINGPROG:2READYQUEUE:-3-0-4BLOCKQLELE:D0L3PRIORITY13293033pPUTIME030kLLTIME303STARTBLOCK2-1-1-1-1BLOCKTIME30000STATEREADYENDREADYREADYREADYRUNNINGPROG:3READYQUElE:-2-0-4BLOCK_QUEUE:ID0123PRIORITY14293130fcPUTIME0311ALLTIME3052STARTBLQCK2-1-1-1-1BLOCKTIME30000RATEREADYEN

16、DREADYREADYREADY2號(hào)進(jìn)程執(zhí)行一次后,優(yōu)先級(jí)由33降低到30,于是3號(hào)進(jìn)程成為當(dāng)前進(jìn)程,2號(hào)進(jìn)程進(jìn)入就緒隊(duì)列等待。BlCAWINDOWS5y5tem32cmd.exeXRUNNINGPROG:3READYQUEUE:-2-0-4BLOCKQUEUE:AD0L23PRIORITY14293130CPUTIME0311Rlltime3052STARTBLOCK2-1-1-1-1BLjOCKTIME30000STATEREADYRUNNINGPROG:2READYQl:El:E:-3-0-4BLOCKQUEUE:ENDREADYREADYREADYID0L234PRIORITY1529

17、28316fPUTME03210LLTIME30424STARTBLOCK2-1-1-1-1BLOCKTIME30000CTATEREADYENDREADYREADYREADY同理,執(zhí)行一次后,3號(hào)進(jìn)程的優(yōu)先級(jí)由33降低到30,2號(hào)進(jìn)程再次成為當(dāng)前進(jìn)程,3號(hào)進(jìn)程進(jìn)入就緒隊(duì)列等待。這個(gè)過(guò)程會(huì)重復(fù)幾次,就不重復(fù)了。mCAWINDOWS55tem32cmd.e3ce-XRUNNINGPROG:3READYQUEUE:-2-0-4BLOCKQLELE:ID0123PRIORITYL8292726fPUTME0333ALLTIME3030STARTBLOCK2-1-1-1-1ELOCKTIME30000

18、RATEREADYENDREADYENDREADYKUNNING-PROG:2READY_QLELE:-0-4BLOCK_QUEUE:D0L234PRIORITY1929242610fPUTME03430LLTIME30204STARTBLOCK2-1-1-1-1BLOCKTIME30000CTATEREADYENDREADYENDREADY3號(hào)進(jìn)程執(zhí)行完畢后退出,2號(hào)進(jìn)程成為當(dāng)前進(jìn)程。EHAWINDOWS5y5tem32cmd.eMe-XRUNNINGPROG:2READY_QLELE:-0-4BbOCK.QUEUE:D0L234PRIORITY2129182612CPUTIME03630R

19、lltime30004STARTBLOCK2-1-1-1-1BLjOCKTIME30000STATEREADYENDENDENDREADYRUNNINGPROG:0READYQUEUE:-4BLOCK_QUEUE:ID0L234PRIORITY1829182613pUTIMEL3e30LLTIME20004STARTBLOCK1-1-1-1-1BLQCKTIME30000CTATEREADYENDENDENDREADY2號(hào)進(jìn)程執(zhí)行完畢后,0號(hào)進(jìn)程成為當(dāng)前進(jìn)程。mCAWINDOWSsystem32cmd.exe一XRUNNINGPROG:0READYQUEUE:-4BLOCKQVELE:ID01

20、234IPRIORITY1529182614pUTIME23630Rlltime10004STARTBLOCK0-1-1-1-1BbOCKTIME30000CTATEREADYENDENDENDREADYRUNNINGPROG:4READYQUEUE:N.OCK,QLELE:-XOD0L34PRIORITY1229182614CPUTIME2331Rlltime1003STARTBLOCK0-1-1-1-1BbOCKTIME20000RATEBLOCKENDENDENDREADY0號(hào)進(jìn)程執(zhí)行2次后,startblock為0了,進(jìn)入阻塞隊(duì)列,停止運(yùn)行,4號(hào)進(jìn)程開(kāi)始執(zhí)行。1i5CAWINDOWSy

21、5tem32cmdjeiOID0L3PRIORITY1229182611CPUTIME233RlltimeL00fSTARTBLOCK0-1-1-I-1BLjOCKTIMEL0000STATEBLOCKENDENDENDREADYRUNNINGPROG:4READYQUEUE:-QBLOCK.QVEIE:ID0L234PRIORITYL22918268fPUTME23633ALLTIMEL0001STARTBLOCK0-1-1-1-1BLOCKTIME00000CTATEREADYENDENDENDREADY4號(hào)進(jìn)程運(yùn)行幾次后,0號(hào)進(jìn)程的blocktime為0了,0號(hào)進(jìn)程從阻塞隊(duì)列轉(zhuǎn)入就緒隊(duì)列mj&tSCzVWINDOWSVsystemJZXcmd.ese-XRUNNINGPROG:4READYQUEUE

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論