處理器調(diào)度之動(dòng)態(tài)優(yōu)先數(shù)調(diào)度算法_第1頁
處理器調(diào)度之動(dòng)態(tài)優(yōu)先數(shù)調(diào)度算法_第2頁
處理器調(diào)度之動(dòng)態(tài)優(yōu)先數(shù)調(diào)度算法_第3頁
處理器調(diào)度之動(dòng)態(tài)優(yōu)先數(shù)調(diào)度算法_第4頁
處理器調(diào)度之動(dòng)態(tài)優(yōu)先數(shù)調(diào)度算法_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、1處理機(jī)調(diào)度1.1實(shí)驗(yàn)內(nèi)容及要求實(shí)驗(yàn)內(nèi)容:按優(yōu)先數(shù)調(diào)度算法實(shí)現(xiàn)處理器調(diào)度。實(shí)驗(yàn)要求:能接受鍵盤輸入的進(jìn)程數(shù)、進(jìn)程標(biāo)識(shí)、進(jìn)程優(yōu)先數(shù)及要求運(yùn)行時(shí)間,能顯示每次進(jìn)程調(diào)度的情況:運(yùn)行進(jìn)程、就緒進(jìn)程和就緒進(jìn)程的排列情況。1.2實(shí)驗(yàn)?zāi)康谋緦?shí)驗(yàn)?zāi)M在單處理器環(huán)境下的處理器調(diào)度,加深了解處理器調(diào)度工作。1.3實(shí)驗(yàn)環(huán)境本實(shí)驗(yàn)的設(shè)計(jì)基于Windows7操作系統(tǒng)DevC+5.11環(huán)境,用C語言實(shí)現(xiàn)編程。1.4實(shí)驗(yàn)思路每個(gè)進(jìn)程用一個(gè)PCB來代表。PCB的結(jié)構(gòu)為:進(jìn)程名作為進(jìn)程標(biāo)識(shí)。優(yōu)先數(shù)賦予進(jìn)程的優(yōu)先數(shù),調(diào)度時(shí)總是選取優(yōu)先數(shù)大的進(jìn)程先執(zhí)行。要求運(yùn)行時(shí)間假設(shè)進(jìn)程需要運(yùn)行的單位時(shí)間數(shù)。狀態(tài)假設(shè)兩種狀態(tài):就緒和結(jié)束,用R表

2、示就緒,用E表示結(jié)束。初始狀態(tài)都為就緒狀態(tài)。指針按優(yōu)先數(shù)的大小把5個(gè)進(jìn)程連成隊(duì)列,用指針指出下一個(gè)進(jìn)程PCB的首地址。開始運(yùn)行之前,為每個(gè)進(jìn)程確定它的“優(yōu)先數(shù)”和“要求運(yùn)行時(shí)間”。通過鍵盤輸入這些參數(shù)。處理器總是選擇隊(duì)首進(jìn)程運(yùn)行。采用動(dòng)態(tài)改變優(yōu)先數(shù)的辦法,進(jìn)程每運(yùn)行1次,優(yōu)先數(shù)減1,要求運(yùn)行時(shí)間減1。進(jìn)程運(yùn)行一次后,若要求運(yùn)行時(shí)間不等于0,則將它加入就緒隊(duì)列,否則,將狀態(tài)改為“結(jié)束”,退出就緒隊(duì)列。若就緒隊(duì)列為空,結(jié)束,否則轉(zhuǎn)到(3)重復(fù)。1.5數(shù)據(jù)結(jié)構(gòu)與全局變量typedefstructpcbintpname;/進(jìn)程名intpriority;/優(yōu)先級(jí)intrunTime;/所需時(shí)間intst

3、ate;/狀態(tài)struetpcb*next;/下一個(gè)進(jìn)程控制塊PCB;/進(jìn)程控制塊intnum;/存儲(chǔ)進(jìn)程數(shù)PCBreadyHead;/頭結(jié)點(diǎn),不存儲(chǔ)進(jìn)程PCB*readyEnd;/指向尾結(jié)點(diǎn)的指針1.6函數(shù)說明主函數(shù)main()輸入進(jìn)程數(shù)并調(diào)createProcess()初始化進(jìn)程;若有進(jìn)程,則依次調(diào)用sortProcess()、runProcess()、printProcessLink()和printProcesslnfo()。進(jìn)程創(chuàng)建函數(shù)createProcess()輸入進(jìn)程標(biāo)識(shí)、優(yōu)先級(jí)和運(yùn)行時(shí)間進(jìn)行初始化。進(jìn)程排序函數(shù)sortProcess()用冒泡排序算法根據(jù)進(jìn)程的優(yōu)先級(jí)進(jìn)行降序排序

4、,每次排序之后優(yōu)先級(jí)最高的進(jìn)程放在就緒隊(duì)列首。進(jìn)程運(yùn)行函數(shù)runProcess()將數(shù)組首的進(jìn)程優(yōu)先級(jí)和所需時(shí)間減1;若剩余所需時(shí)間為0則PCB狀態(tài)標(biāo)記為E(結(jié)束)。輸出函數(shù)printProcessLink()和printProcessInfo()printProcessLink()輸出進(jìn)程鏈,printProcessInfo()輸出進(jìn)程控制塊詳細(xì)信息。1.7運(yùn)行結(jié)果表1.1進(jìn)程數(shù)5序號(hào)優(yōu)先級(jí)運(yùn)行時(shí)間134252341415523對(duì)表1.1數(shù)據(jù)的運(yùn)行結(jié)果:il2222NO.1InputInputHO.3InputInputprocessinfornationbeforerunning:NAME

5、processinfornationbeforerunning:NAMEprocessinfornationbeforerunning:NAME444readyreadyreadyreadyreadyreadyreadyreadyreadyreadyreadyreadyreadyready4processlink:2-3-1-5-44processlink:2-1-5-4processname:1ppiority:3FunTime:4processname:2priority:5FunTime:2processname:3priority:4punTime:1processname:4prio

6、riti/:lrunTime:5processname:5priority:2runTime:3Houmanyprocessdoyouuanttorun:5InputPRIORITVRUNTIMESTATUSNEXTPRIORITYRUNTIMESTATUSNEXTPRIORITVRUNTIMESTATUSNEXT4processlink:13-2-1-5-4(Processrun:33isterminatedprocesspun:22isterminatedxhjcxhxjocxjocxhjcxhjc王111扌守尢7tr?i周底畀_辛主iC*聊!?卜干里i周hjcxhjoocxjocxjoc

7、xhjcxhxk2processinfornationbeforerunning:NAMEPRIORITYRUNTIMESTATUSNEXT241ready1134ready5523ready4415readyprocesslink:2-1-5-4processrun:2isterminatedprocessinformationbeforerunning:NAMEPRIORITYRUNTIMESTATUSNEXT134ready5523ready4415readyprocesslink:l-5-4processpun:1NAMEPRIORITYRUNTIMESTATUS523ready123

8、ready415readyprocesslink:5-1-4processpun:infornationbeforerunning:processNEXT14processNAMEinfornationbeforerunning:PRIORITYRUNTIMESTATUSNEXTreadyreadyreadyprocessl-4-5link:process1run:processinformationbeforerunning:NAMEPRIORITYRUNTIMESTATUSNEXT1processlink:4-5-1readyreadyreadyprocesspun:44Processex

9、itedaftei*25.2?secondswithyetuynvalue0niUlOAWBIBB-n|xprocessinformationbeforerunning:NAMEPRIORITYRUNTIMESTATUSNEXTprocessl-4-5link:process1run:processinformationreadyreadyready45beforerunning:processinformationbeforerunning:NAMEPRIORITVRUNTIME8THTU8NEXT404ready5501ready1101ready5-1processrun:4proces

10、sinformationbeforerunningNAMEPRIORITYRUNTIMESTATUSNEXT501ready1101ready44-13ready1-4processrun:55isterminatedNAMEPRIORITYRUNTIMESTATUSNEXT14processlink:l-4processrun:11isterminated0-1readyready4processinformationbeforerunning:NAMEPRIORITYRUNTIMESTATUSNEXT4processlink:4processrun:ready1.8實(shí)驗(yàn)心得指針操作是真的煩

11、。1.9實(shí)驗(yàn)代碼#include#include#include#include#defineN32voidcreateProcess();voidsortProcess();voidprintProcessLink();voidprintProcessInfo();voidrunProcess();typedefstructpcbcharpnameN;進(jìn)程名intpriority;/進(jìn)程優(yōu)先級(jí)intrunTime;/進(jìn)程還需運(yùn)行的時(shí)間片charstate;/R代表ready,E代表endstructpcb*next;PCB;intnum;/進(jìn)程數(shù)PCBreadyHead;/頭結(jié)點(diǎn),不存儲(chǔ)進(jìn)程

12、PCB*readyEnd;/尾結(jié)點(diǎn)指針intmain()j/*X1111A-g-*-I-J#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*1-,|printf(*實(shí)習(xí)1-1按優(yōu)先級(jí)調(diào)度算法實(shí)現(xiàn)處理器調(diào)度*n);.jX1111A-g-*-I-J#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J

13、*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*#J*1-pname);printf(%sisrunning.n,readyHead.next-pname);printf(%sendsafter%dslice(s).,readyHead.next-pname,readyHead.next-runTime);elsewhile(readyHead.next!=NULL)sortProce

14、ss();printProcessInfo();printProcessLink();runProcess();return0;voidcreateProcess()PCB*p,*prior;printf(Howmanyprocessdoyouwanttorun:);scanf(%d,&num);while(numnext=p;for(inti=0;ipname);printf(priority:);scanf(%d,&(p-priority);printf(runTime:);scanf(%d,&(p-runTime);p-state=R;p-next=(PCB*)malloc(sizeof

15、(PCB);prior=p;p=p-next;free(p);p=NULL;prior-next=NULL;readyEnd=prior;printf(n);voidsortProcess()charnameN;inti,j,priorityNum,timeNum;PCB*p,*rear;for(p=readyHead.next;p!=NULL;p=p-next)for(rear=p-next;rear!=NULL;rear=rear-next)if(p-prioritypriority)strcpy(name,p-pname);priorityNum=p-priority;timeNum=p

16、-runTime;strcpy(p-pname,rear-pname);p-priority=rear-priority;p-runTime=rear-runTime;strcpy(rear-pname,name);rear-priority=priorityNum;rear-runTime=timeNum;voidprintProcessLink()PCB*p=readyHead.next;printf(processlink:n);while(p!=NULL)printf(%s,p-pname);p=p-next;if(p!=NULL)printf(-);printf(n);voidprintProcessInfo()PCB*p=readyHead.next;printf(processinformationbeforerunning:n);printf(=n);printf(NAMEPRIORITYRUNTIMESTATUSNEXTn);printf(=n);while(p!=NULL)printf(%-16s%-8d%-8d%-8s%sn,p-pname,p-priority,p-runTime,(p-state=R)?ready:end,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(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)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論