動態(tài)高優(yōu)先權(quán)優(yōu)先_第1頁
動態(tài)高優(yōu)先權(quán)優(yōu)先_第2頁
動態(tài)高優(yōu)先權(quán)優(yōu)先_第3頁
動態(tài)高優(yōu)先權(quán)優(yōu)先_第4頁
動態(tài)高優(yōu)先權(quán)優(yōu)先_第5頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、操作系統(tǒng)課程實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱:動態(tài)高優(yōu)先權(quán)優(yōu)先姓名:學(xué)號:地點(diǎn):指導(dǎo)老師專業(yè)班級一、實(shí)驗(yàn)內(nèi)容:1、實(shí)驗(yàn)內(nèi)容:2、模擬實(shí)現(xiàn)動態(tài)咼優(yōu)先權(quán)優(yōu)先(若數(shù)值越大優(yōu)先權(quán)越咼,每運(yùn)行一個時間單位優(yōu)先權(quán)n,若數(shù)值越小優(yōu)先權(quán)越高,沒運(yùn)行一個時間單位優(yōu)先權(quán)+n),具體如下:3、設(shè)置作業(yè)體:作業(yè)名,作業(yè)的到達(dá)時間,服務(wù)時間,初始優(yōu)先權(quán),作業(yè)狀態(tài)(W等待,R運(yùn)行,F完成),作業(yè)間的鏈接指針4、作業(yè)初始化:由用戶輸入作業(yè)名、服務(wù)時間、初始優(yōu)先權(quán)進(jìn)行初始化,同時,初始化作業(yè)的狀態(tài)為W。5、顯示函數(shù):在作業(yè)調(diào)度前、調(diào)度中和調(diào)度后進(jìn)行顯示。6、排序函數(shù):對就緒狀態(tài)的作業(yè)按照優(yōu)先權(quán)排序。優(yōu)先權(quán)相同時進(jìn)入等待隊(duì)列時間早的作業(yè)在前。

2、注意考慮到達(dá)時間7、調(diào)度函數(shù):每次從等待隊(duì)列隊(duì)首調(diào)度優(yōu)先權(quán)最咼的作業(yè)執(zhí)行,狀態(tài)變化。并在執(zhí)行一個時間單位后優(yōu)先權(quán)變化,服務(wù)時間變化,狀態(tài)變化。當(dāng)服務(wù)時間為0時,狀態(tài)變?yōu)镕。8、刪除函數(shù):撤銷狀態(tài)為F的作業(yè)。實(shí)驗(yàn)要求:9、測試數(shù)據(jù)可以隨即輸入或從文件中讀入。10、必須要考慮到作業(yè)的到達(dá)時間11、最終能夠計(jì)算每一個作業(yè)的周轉(zhuǎn)時間。三、實(shí)驗(yàn)代碼#include#includestructPCBcharp_name20;intp_priority;intp_needTime;intp_runTime;charp_state;structPCB*next;voidHighPriority();voidR

3、oundRobin();voidInformation();charChoice();structPCB*SortList(PCB*HL);intmain()Information();charchoice=Choice();switch(choice)case1:system(cls);HighPriority();break;case2:system(cls);RoundRobin();break;default:break;system(pause);return0;charChoice()printf(nn);printf(n);printf(printf(nnn);printf(pr

4、intf(printf(printf(#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ìn)程調(diào)度演示n);#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*演示

5、最高優(yōu)先數(shù)優(yōu)先算法。n);演示輪轉(zhuǎn)法算法。n);退出程序。nnnn);選擇進(jìn)程調(diào)度方法:);charch=getchar();returnch;system(cls);voidHighPriority()structPCB*processes,*pt;/pt作為臨時節(jié)點(diǎn)來創(chuàng)建鏈表processes=pt=(structPCB*)malloc(sizeof(structPCB);for(inti=0;i!=5;+i)structPCB*p=(structPCB*)malloc(sizeof(structPCB);printf(進(jìn)程號No.%d:n,i);printf(輸入進(jìn)程名:);scanf(

6、%s,p-p_name);printf(輸入進(jìn)程優(yōu)先數(shù):);scanf(%d,&p-p_priority);printf(輸入進(jìn)程運(yùn)行時間:);scanf(%d,&p-p_needTime);p-p_runTime=0;p-p_state=W;p-next=NULL;pt-next=p;pt=p;printf(nn);getchar();/接受回車/processes作為頭結(jié)點(diǎn)來存儲鏈表processes=processes-next;intcases=0;structPCB*psorted=processes;while(1)+cases;pt=processes;/對鏈表按照優(yōu)先數(shù)排序/p

7、sorted用來存放排序后的鏈表psorted=SortList(psorted);printf(Theexecutenumber:%dnn,cases);printf(*當(dāng)前正在運(yùn)行的進(jìn)程是:%sn,psorted-p_name);psorted-p_state=R;printf(qnamestatesuperndtimeruntimen);printf(%st%ct%dt%dt%dtnn,psorted-p_name,psorted-p_state,psorted-p_priority,psorted-p_needTime,psorted-p_runTime);pt-p_state=W;p

8、sorted-p_runTime+;psorted-p_priority-;printf(*當(dāng)前就緒狀態(tài)的隊(duì)列為:nn);/pt指向已經(jīng)排序的隊(duì)列pt=psorted-next;while(pt!=NULL)printf(qnamestatesuperndtimeruntimen);printf(%st%ct%dt%dt%dtnn,pt-p_name,pt-p_state,pt-p_priority,pt-p_needTime,pt-p_runTime);pt=pt-next;/pt指向已經(jīng)排序的鏈表,判斷鏈表是否有已用時間啊等于需要時間的pt=psorted;structPCB*ap;ap=

9、NULL;ap指向pt的前一個節(jié)點(diǎn)while(pt!=NULL)if(pt-p_needTime=pt-p_runTime)if(ap=NULL)pt=psorted-next;psorted=pt;elseap-next=pt-next;ap=pt;pt=pt-next;if(psorted-next=NULL)break;getchar();structPCB*SortList(PCB*HL)structPCB*SL;SL=(structPCB*)malloc(sizeof(structPCB);SL=NULL;structPCB*r=HL;while(r!=NULL)structPCB*

10、t=r-next;structPCB*cp=SL;structPCB*ap=NULL;while(cp!=NULL)if(r-p_prioritycp-p_priority)break;elseap=cp;cp=cp-next;if(ap=NULL)r-next=SL;SL=r;elser-next=cp;ap-next=r;r=t;returnSL;/輪轉(zhuǎn)算法voidRoundRobin()structPCB*processes,*pt;/pt作為臨時節(jié)點(diǎn)來創(chuàng)建鏈表processes=pt=(structPCB*)malloc(sizeof(structPCB);for(inti=0;i!=

11、5;+i)structPCB*p=(structPCB*)malloc(sizeof(structPCB);printf(進(jìn)程號No.%d:n,i);printf(輸入進(jìn)程名:);scanf(%s,p-p_name);printf(輸入進(jìn)程運(yùn)行時間:);scanf(%d,&p-p_needTime);p-p_runTime=0;p-p_state=W;p-next=NULL;pt-next=p;pt=p;printf(nn);getchar();/接受回車/processes作為頭結(jié)點(diǎn)來存儲鏈表processes=processes-next;intcases=0;while(1)+cases

12、;pt=processes;printf(Theexecutenumber:%dnn,cases);printf(*當(dāng)前正在運(yùn)行的進(jìn)程是:sn,pt-p_name);pt-p_state=R;printf(qnamestatesuperndtimeruntimen);printf(%st%ct%dt%dt%dtnn,pt-p_name,pt-p_state,pt-p_priority,pt-p_needTime,pt-p_runTime);pt-p_state=W;pt-p_runTime+;pt-p_priority-;printf(*當(dāng)前就緒狀態(tài)的隊(duì)列為:nn);pt=pt-next;wh

13、ile(pt!=NULL)printf(qnamestatesuperndtimeruntimen);printf(%st%ct%dt%dt%dtnn,pt-p_name,pt-p_state,pt-p_priority,pt-p_needTime,pt-p_runTime);pt=pt-next;/檢測是否運(yùn)行時間等于需要時間,是的話從隊(duì)列里面刪除,不是的話加到隊(duì)列最尾部pt=processes;if(pt-p_needTime=pt-p_runTime)pt-p_state=C;pt=processes-next;processes=pt;elseif(pt-next!=NULL)/尋找最

14、后一個節(jié)點(diǎn)while(pt-next!=NULL)pt=pt-next;structPCB*ptem;/臨時節(jié)點(diǎn)用來幫助把頭結(jié)點(diǎn)插到尾部ptem=processes-next;pt-next=processes;processes-next=NULL;processes=ptem;pt=processes;if(pt=NULL)break;getchar();四、實(shí)驗(yàn)結(jié)果輸入進(jìn)程名字,進(jìn)程優(yōu)先數(shù)和進(jìn)程時間:5:可.1a數(shù)時:仃.0名曜耳進(jìn)進(jìn)進(jìn)賞入入3:間h熱州:仃.1名饑邁號進(jìn)進(jìn)進(jìn)費(fèi)入入8:可.1C數(shù)時:fe行.2名他邁1號進(jìn)進(jìn)進(jìn)費(fèi)入入ai:.出數(shù)時:姐行.3名他邁號進(jìn)進(jìn)進(jìn)黛入入ai1:可.1

15、E數(shù)時:姐行.4名他邁號進(jìn)進(jìn)進(jìn)費(fèi)入入c*:個人C+sDebugs.eze圖3Theexecutenumbei:1訂4十4V-乙-M=Lnscndtime0runtime耳MX耳qnameC3刖止仕旦仃曲進(jìn)性疋:stateRsuper81耳mt耳當(dāng)前就緒狀態(tài)的隊(duì)列為:qnamestatesuperndtimeruntimedU633qnamestatesupeindtimeruntimeau530qnamestatesupeindtin巳runtinebV320qnamestatesuperndtimepuntimeeU140圖4圖 s0e:汕*F:AC+sDe=bugs.exeTheexecL

16、itenLimber:2i當(dāng)前就緒伏態(tài)的隊(duì)列為superndtine0runtineqnamesuperndtivne0runtineqnameesuper14nH七iiTiE0runtineTheexecutenLimbep:31當(dāng)前就緒狀態(tài)的隊(duì)列為qn-amesuperndtine0runtimesuper14ndtine0runtineqn-ameqname卜*當(dāng)前正在運(yùn)行的進(jìn)程是=donamestatesuperndtinedR630puntine嚴(yán)*當(dāng)前正在運(yùn)行的進(jìn)程是=donamestatesuperncItivnEdR531puntineqnamesuperndtinepunti

17、neTheexecutenLimber:41._L1.亠1I.11LI當(dāng)前止往運(yùn)行旳迸程是:aqnamestatesuperndtimeruntimeaR530:KXNH當(dāng)前就緒狀態(tài)的隊(duì)列為:qnamestatesupeindtin)eruntinedR432qnamestatesupeindtin)eruntinebU320qnanestatesuperndtimepuntineeU140圖 qnameqnameqnameqnameqnameqname1qnaneeTheexecutenuinbei:5iuntimeIuntimeruntimesuperiuntimestatesuperTh

18、eexecutenumber=6iuntimeiuntimesuperiuntimestateruntimesuperstateRndtime0ndtime0ndtime&ndtime0ndtime2ndtime2i當(dāng)前就緒狀態(tài)的隊(duì)列為:statesupep4K*當(dāng)前就緒狀態(tài)的隊(duì)列為:c*F:4wC+sDebugs.exeH*當(dāng)前正在運(yùn)行的進(jìn)程是:玄ndtime1h*當(dāng)前正在運(yùn)彳亍的進(jìn)程是:dndtime圖7Theexecutenumber:7H*當(dāng)前正在運(yùn)行的進(jìn)程是:已qnameastnteR3super3rMtim亡2runtime當(dāng)前就緒狀態(tài)的隊(duì)列九qnamestatesuperndtimepuntimetoW320qnamestatesuperndtimeruntimeEu140theexecutenumber:8卜*當(dāng)刖正在運(yùn)行的進(jìn)程是bnnamestatesupepndtimeruntimehR3204當(dāng)前就緒狀態(tài)的隊(duì)列為:qnamestatesupei*imeruntimeM140pTheexe

溫馨提示

  • 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論