資源描述:
《基于優(yōu)先級(jí)的時(shí)間片輪轉(zhuǎn)調(diào)度算法調(diào)度處理器》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、#include#include#include#include/*進(jìn)程控制塊數(shù)據(jù)結(jié)構(gòu)*/typedefstructnode{charname[10];/*進(jìn)程名*/intprio;/*進(jìn)程優(yōu)先級(jí)*/intround;/*進(jìn)程分配的時(shí)間片*/intcputime;/*進(jìn)程消耗的CUP時(shí)間*/intneedtime;/*進(jìn)程需要的CUP時(shí)間*/intcount;/*進(jìn)程運(yùn)行時(shí)間*/charstate;/*進(jìn)程的狀態(tài):'R':運(yùn)行,'W':等待,'F':結(jié)束*/structnode*next;/*指向下一個(gè)
2、進(jìn)程的指針*/}PCB;PCB*finish,*ready,*tail,*run;/*指向三個(gè)隊(duì)列的隊(duì)首的指針,tail為就緒隊(duì)列的隊(duì)尾指針*/intN;/*定義進(jìn)程的數(shù)目*//*函數(shù)功能:將進(jìn)程就緒隊(duì)列中第一個(gè)放進(jìn)就緒隊(duì)列函數(shù)原型:voidfirstin(void)函數(shù)參數(shù):void函數(shù)返回值:void作者:李文塔WentaLi日期:2008年5月22日12:19*/voidfirstin(void){if(ready!=NULL){run=ready;ready=ready->next;run->state='R';run->next=NULL;}else{run=NULL
3、;}}/*函數(shù)功能:輸出進(jìn)程信息的標(biāo)題函數(shù)函數(shù)原型:voidprt1(chara)函數(shù)參數(shù):chara:a=='p'為優(yōu)先級(jí),=='r'為時(shí)間片輪轉(zhuǎn)函數(shù)返回值:void作者:李文塔WentaLi日期:2008年5月21日11:19*/voidprt1(chara){if(toupper(a)=='P'){printf("namecputimeneedtimeprioritystate");}else{printf("namecputimeneedtimecountroundstate");}}/*函數(shù)功能:輸出單個(gè)進(jìn)程信息的函數(shù)函數(shù)原型:voidprt2(chara,P
4、CB*p)函數(shù)參數(shù):chara:a=='p'為優(yōu)先級(jí),=='r'為時(shí)間片輪轉(zhuǎn)PCB*p為指向待輸出的進(jìn)程控制塊的指針函數(shù)返回值:void*/voidprt2(chara,PCB*p){if(toupper(a)=='P'){printf("%-10s,%-10d,%-10d,%-10d,%-5c",p->name,p->cputime,p->needtime,p->prio,p->state);}else{printf("%-10s,%-10d,%-10d,%-10d,%-10d,%-5c",p->name,p->cputime,p->needtime,p->count
5、,p->round,p->state);}}/*函數(shù)功能:輸出所有進(jìn)程信息的函數(shù)函數(shù)原型:voidprt(charalgo)函數(shù)參數(shù):chara:a=='p'為優(yōu)先級(jí),=='r'為時(shí)間片輪轉(zhuǎn)函數(shù)返回值:void*/voidprt(charalgo){PCB*p;prt1(algo);if(run!=NULL){prt2(algo,run);}p=ready;while(p!=NULL){prt2(algo,p);p=p->next;}p=finish;while(p!=NULL){prt2(algo,p);p=p->next;}getchar();}/*函數(shù)功能:優(yōu)先級(jí)法調(diào)度將
6、進(jìn)程插入到就緒隊(duì)列算法函數(shù)原型:voidinsert1(PCB*q)函數(shù)參數(shù):PCB*q待插入的隊(duì)列進(jìn)程控制塊優(yōu)先級(jí)越高,插入越靠前函數(shù)返回值:void*/voidinsert1(PCB*q){PCB*p,*s,*r;/*p,r用來(lái)控制就緒隊(duì)列滾動(dòng),S指向插入的隊(duì)列*/intb;/*b作為插入控制標(biāo)志的*/s=q;p=ready;r=p;b=1;if(s->prio>=ready->prio){s->next=ready;ready=s;}else{while((p!=NULL)&&b){if(p->prio>=s->prio){r=p;p=p->next;}else{b=0;
7、}}s->next=p;r->next=s;}}/*函數(shù)功能:時(shí)間片輪轉(zhuǎn)算法調(diào)度將進(jìn)程插入到就緒隊(duì)列算法函數(shù)原型:voidinsert2(PCB*q)函數(shù)參數(shù):PCB*q待插入的隊(duì)列進(jìn)程控制塊函數(shù)返回值:void*/voidinsert2(PCB*q){tail->next=q;tail=q;q->next=NULL;}/*函數(shù)功能:采用優(yōu)先級(jí)進(jìn)程調(diào)度法時(shí),進(jìn)程初始化函數(shù)函數(shù)原型:voidpcreate_task(charalgo)函數(shù)參數(shù):charalgo:函數(shù)返回值:void*/void