高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第1頁
高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第2頁
高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第3頁
高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第4頁
高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

河南工業(yè)大學(xué)實(shí)驗(yàn)報(bào)告課程一計(jì)算機(jī)操作系統(tǒng)實(shí)驗(yàn)名稱高(動態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬系別 信息科學(xué)與工程學(xué)院計(jì)算機(jī)科學(xué)系 專業(yè)班級 實(shí)驗(yàn)日期2012-10-26姓名 學(xué)號 教師審批簽字實(shí)驗(yàn)?zāi)康耐ㄟ^動態(tài)優(yōu)先權(quán)算法的模擬加深對進(jìn)程概念和進(jìn)程調(diào)度過程的理解。實(shí)驗(yàn)環(huán)境裝有操作系統(tǒng)WindowsXP和開發(fā)工具VC++6.0,內(nèi)存在256M以上的微機(jī);或者:裝有Linux(Fedora7)操作系統(tǒng)和gcc編譯器,內(nèi)存在256M以上的微機(jī)。實(shí)驗(yàn)內(nèi)容用C語言來實(shí)現(xiàn)對N個進(jìn)程采用動態(tài)優(yōu)先權(quán)優(yōu)先算法的進(jìn)程調(diào)度。每個用來標(biāo)識進(jìn)程的進(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時間CPUTIME;進(jìn)程還需占用的CPU時間NEEDTIME。當(dāng)進(jìn)程運(yùn)行完畢時,NEEDTIME變?yōu)?;進(jìn)程的阻塞時間STARTBLOCK,表示當(dāng)進(jìn)程再運(yùn)行STARTBLOCK個時間片后,進(jìn)程將進(jìn)入阻塞狀態(tài);進(jìn)程被阻塞的時間BLOCKTIME,表示已阻塞的進(jìn)程再等待BLOCKTIME個時間片后,進(jìn)程將轉(zhuǎn)換成就緒狀態(tài);進(jìn)程狀態(tài)STATE;(READY,RUNNING,BLOCK,FINISH)隊(duì)列指針NEXT,用來將PCB排成隊(duì)列。優(yōu)先數(shù)改變的原則:進(jìn)程在就緒隊(duì)列中呆一個時間片,優(yōu)先數(shù)增加1;進(jìn)程每運(yùn)行一個時間片,優(yōu)先數(shù)減3。假設(shè)在調(diào)度前,系統(tǒng)中有5個進(jìn)程,它們的初始狀態(tài)如下:ID01234PRIORITY93830290CPUTIME00000NEEDTIME33634STARTBLOCK2-1-1-1-1BLOCKTIME30000STATE READY READY READY READY READY為了清楚地觀察進(jìn)程的調(diào)度過程,程序應(yīng)將每個時間片內(nèi)的進(jìn)程的情況顯示出來參照的具體格式如下:RUNNINGPROCESS:$id0READYQUEUE:$id1->$id2BLOCKQUEUE:$id3->$id4FINISHQUEUE:$id0->$id1->$id2->$id3->$id4IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME0XXXXXXXXXXXX1XXXXXXXXXXXX2XXXXXXXXXXXX3XXXXXXXXXXXX4XXXXXXXXXXXX實(shí)驗(yàn)要求將源程序(priority.c)和程序運(yùn)行結(jié)果寫入實(shí)驗(yàn)報(bào)告。將該算法執(zhí)行過程與高響應(yīng)比優(yōu)先調(diào)度算法的執(zhí)行過程進(jìn)行比較實(shí)驗(yàn)過程及結(jié)果(1).代碼:#include<stdio.h>#include<string.h>#include<stdlib.h>char*State[]={"READY","RUNNING","BLOCK","FINISH"};typedefstructPCB{intid;intpriority;intcputime;intneedtime;intstartblock;intblocktime;char*state;structPCB*next;structPCB*nt;}PCB;PCB*Ready,*Block,*Finish,*Runing,*ALL;PCB*findHighest();voidinsert(PCB*node,PCB*insert,inti);voidModifyPriority();voidModifyBlock();voidBlockToReady();voidPrint();voidFreeAllPCB();voidinit(){PCB*pro=(PCB*)malloc(sizeof(PCB));Ready->next=ALL=pro;pro->id=0;pro->priority=9;pro->cputime=0;pro->needtime=3;pro->startblock=2;pro->blocktime=3;pro=pro->next=pro->nt=(PCB*)malloc(sizeof(PCB));pro->id=1;pro->priority=38;pro->cputime=0;pro->needtime=3;pro->startblock=-1;pro->blocktime=0;pro=pro->next=pro->nt=(PCB*)malloc(sizeof(PCB));pro->id=2;pro->priority=30;pro->cputime=0;pro->needtime=6;pro->startblock=-1;pro->blocktime=0;pro=pro->next=pro->nt=(PCB*)malloc(sizeof(PCB));pro->id=3;pro->priority=29;pro->cputime=0;pro->needtime=3;pro->startblock=-1;pro->blocktime=0;pro=pro->next=pro->nt=(PCB*)malloc(sizeof(PCB));pro->id=4;pro->priority=0;pro->cputime=0;pro->needtime=4;pro->startblock=-1;pro->blocktime=0;pro->next=pro->nt=NULL;}PCB*findHighest(){PCB*pro,*highest;PCB*propre=Ready;PCB*highpre=Ready;highest=pro=Ready->next;while(pro!=NULL){if(pro->priority>highest->priority){highest=pro;highpre=propre;}propre=propre->next;pro=pro->next;}highpre->next=highest->next;highest->next=NULL;returnhighest;}voidinsert(PCB*node,PCB*insert,inti){node->state=State[i];node->next=insert->next;insert->next=node;}voidModifyPriority(){PCB*p;p=Ready->next;while(p!=NULL){p->priority++;p=p->next;voidModifyBlock(){PCB*p;p=Block->next;while(p!=NULL){p->blocktime--;p=p->next;}}voidBlockToReady(){PCB*p,*pre,*node;pre=Block;p=pre->next;while(p!=NULL){if(p->blocktime==0){p->startblock--;node=p;p=pre->next=node->next;node->next=NULL;insert(node,Ready,0);}else{pre=pre->next;p=p->next;}}}voidPrint(){PCB*pro,*All;if(Runing!=NULL)printf("RUNNINGPROCESS:$id%d\n",Runing->id);printf("READYQUEUE:");pro=Ready->next;while(pro!=NULL){printf("->$id%d",pro->id);pro=pro->next;}puts("");printf("BLOCKQUEUE:");pro=Block->next;while(pro!=NULL){printf("->$id%d",pro->id);pro=pro->next;}puts("");printf("FINISHQUEUE:");pro=Finish->next;while(pro!=NULL){printf("->$id%d",pro->id);pro=pro->next;}puts("");printf("===============================================================\n");printf("IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME\n");All=ALL;while(All!=NULL){printf("%d%10d%10d%10d%8s%10d%11d\n",All->id,All->priority,All->cputime,All->needtime,All->state,All->startblock,All->blocktime);All=All->nt;}}voidFreeAllPCB(){free(Finish);}intmain(void){PCB*pro;Ready=(PCB*)malloc(sizeof(PCB));Block=(PCB*)malloc(sizeof(PCB));Finish=(PCB*)malloc(sizeof(PCB));Ready->next=NULL;Block->next=NULL;Finish->next=NULL;init();while(Ready->next!=NULL){pro=findHighest();Runing=pro;pro->state=State[1];pro->cputime++;pro->needtime--;if(pro->startblock>0){pro->startblock--;}pro->priority-=3;Print();ModifyBlock();ModifyPriority();BlockToReady();if(pro->needtime==0){insert(pro,Finish,3);Runing=NULL;}else{if(pro->startblock==0){insert(pro,Block,2);}else{insert(pro,Ready,0);}Runing=NULL;

Print();FreeAllPCB();return0;}程序運(yùn)行結(jié)果RUNNINGPROCESS:$idl^EADVQUEUE:->$id0->$id2->$id3->$id4BLOCKQUEUE:FINISHQUEUE:IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME0 903READV231 3512READV-10* 3006READV-10□ 2903READV-104 004READV-10誠C:\Windows\system32\cmd£?e4卜jRunningprocess:$idi^EADVQUEUE:->$id0->$id2->$id3->$id4BLOCKQUEUE:FINISHQUEUE:IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01003READV231 3221READV-10* 3106READV-10□ 3003READV-104 104READV-10誠C:\WindoW5\system32\cmd.exe

RUNNINGPROCESS:$id2READVQUEUE:BLOCKQUEUE:FINISHQUEUE:->$idB->$id3->$id4:->$idlIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01203READV231 2930READV-10* 3015READV-103 3203READV-104 3a4READV-10nrawC:\WindDws\system32\cmd,exeRUNNINGPROCESS:$id2READVQUEUE:BLOCKQUEUE:FINISHQUEUE->$id0->$id4:->$id3->$idlIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01803READV231 2930READV-10* 2442READV-10□2630READV-104 904READV-10■誠C:\Wind0ws\system32\cmd.exe

RUNNINGPROCESS:$id0HEADVQUEUE:->$id4BLOCKQUEUE:FINISHQUEUE::->$id2->$id3->$idlIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01812READV131 2930READV-10*1860READV-103 2630READV-104 12a4READV-10rawC:\Windows\system32\cmd.exeRUNNINGPROCESS:$id4READVQUEUE:BLOCKQUEUE:FINISHQUEUE->$idB:->$id2->$id3->$idlIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01521READV0312930READV-1021860READV-1032630READV-1041113READV-10■ 誠C:\Wind0W5\system32\cmd.exeRUNNINGPROCESS:$id4READVQUEUE:BLOCKQUEUE:RUNNINGPROCESS:$id4READVQUEUE:BLOCKQUEUE:->$id0FINISHQUEUE::->$id2->$id3->$idlIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME0 1521READV011 2930READV-10*1860READV-103 2630READV-104 531READV-10rawC:\Windows\systeni32\cmd.exerawC:\Windows\system32\cmd.exe[RUNNINGPROCESS:$id0READVQUEUE:->$id4BLOCKQUEUE:rawC:\Windows\systrawC:\Windows\system32\cmd.exeIDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME01230READV-1012930READV-1021860READV-1032630READV-104531READV-10rrrrawC:\Windows\system32\cmd.exeRUNNINGPROCESS:$id4READVQUEUE:BLOCKQUEUE:FINISHQUEUE:->$id0->$id2->$id3->$idlIDPRI

溫馨提示

  • 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

提交評論