高動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第1頁(yè)
高動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第2頁(yè)
高動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第3頁(yè)
高動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第4頁(yè)
高動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬_第5頁(yè)
已閱讀5頁(yè),還剩7頁(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、河南工業(yè)大學(xué)實(shí)驗(yàn)報(bào)告課程一 計(jì)算機(jī)操作系統(tǒng)實(shí)驗(yàn)名稱高(動(dòng)態(tài))優(yōu)先權(quán)優(yōu)先的進(jìn)程調(diào)度算法模擬系 別信息科學(xué)與工程學(xué)院計(jì)算機(jī)科學(xué)系專業(yè)班級(jí) 實(shí)驗(yàn)日期2012-10-26姓 名 學(xué) 號(hào)教師審批簽字.實(shí)驗(yàn)?zāi)康耐ㄟ^(guò)動(dòng)態(tài)優(yōu)先權(quán)算法的模擬加深對(duì)進(jìn)程概念和進(jìn)程調(diào)度過(guò)程的理解。.實(shí)驗(yàn)環(huán)境裝有操作系統(tǒng) Windows XP和開(kāi)發(fā)工具 VC+6.0,內(nèi)存在256M以上的微機(jī);或者:裝有Linux(Fedora 7)操作系統(tǒng)和gcc編譯器,內(nèi)存在 256M以上的微機(jī)。.實(shí)驗(yàn)內(nèi)容(1)用C語(yǔ)言來(lái)實(shí)現(xiàn)對(duì) N個(gè)進(jìn)程采用動(dòng)態(tài)優(yōu)先權(quán)優(yōu)先算法的進(jìn)程調(diào)度。(2)每個(gè)用來(lái)標(biāo)識(shí)進(jìn)程的進(jìn)程控制塊PCB用結(jié)構(gòu)來(lái)描述,包括以下字段:進(jìn)程標(biāo)識(shí)數(shù)

2、ID;進(jìn)程優(yōu)先數(shù)PRIORITY,并規(guī)定優(yōu)先數(shù)越大的進(jìn)程,其優(yōu)先權(quán)越高;進(jìn)程已占用的 CPU寸間CPUTIME進(jìn)程還需占用的 CPU時(shí)間NEEDTIME當(dāng)進(jìn)程運(yùn)行完畢時(shí),NEEDTIM度為0;進(jìn)程的阻塞時(shí)間STARTBLOCK表示當(dāng)進(jìn)程再運(yùn)行 STARTBLOCK時(shí)間片后,進(jìn) 程將進(jìn)入阻塞狀態(tài);進(jìn)程被阻塞的時(shí)間 BLOCKTIME表示已阻塞的進(jìn)程再等待BLOCKTIMEb時(shí)間片后,進(jìn)程將轉(zhuǎn)換成就緒狀態(tài);進(jìn)程態(tài) STATE (READY, RUNNING, BLOCK, FINISH)隊(duì)列指針NEXT用來(lái)將PC明E成隊(duì)列。(3)優(yōu)先數(shù)改變的原則:進(jìn)程在就緒隊(duì)列中呆一個(gè)時(shí)間片,優(yōu)先數(shù)增加1;進(jìn)程每

3、運(yùn)行一個(gè)時(shí)間片,優(yōu)先數(shù)減3。(4)假設(shè)在調(diào)度前,系統(tǒng)中有5個(gè)進(jìn)程,它們的初始狀態(tài)如下:ID01234PRIORITY93830290CPUTIME00000NEEDTIME33634STARTBLOCK2-1-1-1-1BLOCKTIME30000STATEREADY READY READY READY READY(5)為了清楚地觀察進(jìn)程的調(diào)度過(guò)程,程序應(yīng)將每個(gè)時(shí)間片內(nèi)的進(jìn)程的情況顯示出來(lái), 參照的具體格式如下:RUNNING PROCESS: $id0READY QUEUE: $id1-$id2BLOCK QUEUE: $id3-$id4FINISH QUEUE: $id0-$id1-$id

4、2-$id3-$id4ID PRIORITY CPUTIME NEEDTIME STATE STARTBLOCK BLOCKTIME0XXXXXXXXXXXX1XXXXXXXXXXXX2XXXXXXXXXXXX3XXXXXXXXXXXX4XXXXXXXXXXXX.實(shí)驗(yàn)要求(1)將源程序(priority和程序運(yùn)行結(jié)果寫入實(shí)驗(yàn)報(bào)告。(2)將該算法執(zhí)行過(guò)程與高響應(yīng)比優(yōu)先調(diào)度算法的執(zhí)行過(guò)程進(jìn)行比較。.實(shí)驗(yàn)過(guò)程及結(jié)果.代碼:#include #include #include char *State口 = READY, RUNNING, BLOCK, FINISH;typedef struct PCB

5、 i nt id;nt priority;nt cputime;nt needtime;nt startblock;i nt blocktime; char *state; struct PCB *next; struct PCB *nt; PCB;PCB *Ready, *Block, *Finish, *Runing, *ALL;PCB *findHighest();void insert(PCB *node, PCB *insert, int i);void ModifyPriority();void ModifyBlock();void BlockToReady();void Prin

6、t();void FreeAllPCB();void init()PCB *pro = (PCB *)malloc(sizeof(PCB);Rsady-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

7、 = 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-need

8、time = 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 = Read

9、y;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;return highest;)void insert(PCB *node,PCB *insert,int i)node-state = Statei;node-next = insert-next;i

10、nsert-next = node;)void ModifyPriority()PCB *p;p = Ready-next;while(p !=NULL)p-priority+;p = p-next;void ModifyBlock()(PCB *p;p = Block-next;while(p !=NULL)(p-blocktime-;p = p-next;)void BlockToReady()(PCB *p, *pre, *node;pre = Block;p = pre-next;while(p != NULL) (if(p-blocktime = 0)(p-startblock-;n

11、ode = p;p = pre-next = node-next;node-next = NULL;insert(node, Ready,0);)else(pre = pre-next;p = p-next;)void Print()(PCB *pro, *All;if(Runing != NULL)printf(RUNNING PROCESS: $id%dn, Runing-id); printf(READY QUEUE:);pro = Ready-next; while(pro != NULL) printf(-$id%d, pro-id); pro = pro-next; puts();

12、printf(BLOCK QUEUE:);pro = Block-next; while(pro != NULL) printf(-$id%d, pro-id); pro = pro-next; puts();printf(FINISH QUEUE:);pro = Finish-next; while(pro != NULL) printf(-$id%d, pro-id); pro = pro-next; puts();printf(=n); printf(ID PRIORITY CPUTIME NEEDTIME STATE STARTBLOCK BLOCKTIMEn);Al = ALL;wh

13、ile(All != NULL) printf(%d%10d%10d%10d%8s%10d%11dn,All-id, All-priority,All-cputime, All-needtime, All-state,All-startblock, All-blocktime); All = All-nt; void FreeAllPCB() f ree(Finish); int main(void)(PCB *pro;Ready = (PCB *)malloc(sizeof(PCB);Block = (PCB *)malloc(sizeof(PCB);Finish = (PCB *)mall

14、oc(sizeof(PCB);Ready-next = NULL;Bock-next = NULL;Finish-next = NULL;i nit();while(Ready-next != NULL)(pro = findHighest();Runing = pro;pro-state = State1;pro-cputime+;pro-needtime-;if(pro-startblock 0)(pro-startblock-;pro-priority -= 3;Print();ModifyBlock();ModifyPriority();BlockToReady();if(pro-ne

15、edtime = 0)(insert(pro, Finish, 3);Runing=NULL;else(if(pro-startblock = 0) insert(pro, Block, 2);elseinsert(pro, Ready, 0);Runing=NULL;FreeAllPCB();return 0;程序運(yùn)行結(jié)果STATE STARTBLOCK BLOCKTIME000HEADY READY READY READY READY3 00 03CPUTIME NEEDTINE 03C:Wind owssyste m32 _cm d. exeUINNING PROCESS : Sid2E

16、AD QUEUE: -$id0 0id3 iid4LOCK QUEUE: IHISH QUEUE: -$idlID PRIORITY12293032Ill040READY READY REfiDV READY READY3 00 004PRIORITY182924269UNNING PROCESS: $id2EADY QUEUE: -$idU :id4LOCK QUEUE:IHISH QUEUE: -$id3-$idlCPUTIME NEEDTINE 03C:Wind ov/ssyste m32_cin d .exeSTATE STARTBLOCK BLOCKTIMEEEJ C:Windows

17、.system32cmd.exeRUNNING PROCESS: $id4PEADV QUEUE:BLOCK QUEUE:FINISH QUEUE: -$id0-$id2-$id3-$idlPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME1230AEAD?-102930READY-10186gHEfiDV-102630READY一10340READY-10I 0 1 2 3 4EEJ C:Windowssystem32cnnd.exe.試驗(yàn)中的問(wèn)題將該算法執(zhí)行過(guò)程與高響應(yīng)比優(yōu)先調(diào)度算法的執(zhí)行過(guò)程進(jìn)行比較。為了照顧緊迫型作業(yè), 使之在進(jìn)入系統(tǒng)后便獲得優(yōu)先處理,引入了高優(yōu)先權(quán)優(yōu)先調(diào)度算法。此算法常被用于批處理系統(tǒng),作為作業(yè)調(diào)度算法, 也作為多種操作系統(tǒng)中的進(jìn)程調(diào)度算法,還可用于實(shí)時(shí)系統(tǒng)。 該算法用于作業(yè)調(diào)度時(shí), 系統(tǒng)將從后備隊(duì)列中選擇若 干個(gè)優(yōu)先權(quán)最高的作業(yè)

溫馨提示

  • 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)論