3、i);p=getpch(PCB);printf("輸入進(jìn)程名:");scanf("%s",p->name);printf("輸入進(jìn)程優(yōu)先數(shù):");scanf("%d",&p->super);printf("輸入進(jìn)程運(yùn)行時(shí)間:");scanf("%d",&p->ntime);printf("");p->rtime=0;p->state='w';p->link=NULL;sort();/*調(diào)用sort函數(shù)*/}}intspace(){intl=0;PCB*pr=ready;while(pr!=NULL){l++;pr=pr->
4、link;}return(l);}voiddisp(PCB*pr)/*建立進(jìn)程顯示函數(shù),用于顯示當(dāng)前進(jìn)程*/{printf("qnametstatetsupertndtimetruntime");printf("
5、%st",pr->name);printf("
6、%ct",pr->state);printf("
7、%dt",pr->super);printf("
8、%dt",pr->ntime);printf("
9、%dt",pr->rtime);printf("");}voidcheck()/*建立進(jìn)程查看函數(shù)*/
10、{PCB*pr;printf("****當(dāng)前正在運(yùn)行的進(jìn)程是:%s",p->name);/*顯示當(dāng)前運(yùn)行進(jìn)程*/disp(p);pr=ready;printf("****當(dāng)前就緒隊(duì)列狀態(tài)為:");/*顯示就緒隊(duì)列狀態(tài)*/while(pr!=NULL){disp(pr);pr=pr->link;}}voiddestroy()/*建立進(jìn)程撤消函數(shù)(進(jìn)程運(yùn)行結(jié)束,撤消進(jìn)程)*/{printf("進(jìn)程[%s]已完成.",p->name);free(p);}voidrunning()/*建立進(jìn)程就緒函數(shù)(進(jìn)程運(yùn)行時(shí)間到,置就緒狀
11、態(tài)*/{(p->rtime)++;if(p->rtime==p->ntime)destroy();/*調(diào)用destroy函數(shù)*/else{(p->super)--;p->state='w';sort();/*調(diào)用sort函數(shù)*/}}voidmain()/*主函數(shù)*/{intlen,h=0;charch;input();len=space();while((len!=0)&&(ready!=NULL)){ch=getchar();h++;printf("Theexecutenumber:%d",h);p=ready;ready=p-
12、>link;p->link=NULL;p->state='R';check();running();printf("按任一鍵繼續(xù)......");ch=getchar();}printf("進(jìn)程已經(jīng)完成.");ch=getchar();}圖2-1最高優(yōu)先數(shù)優(yōu)先的調(diào)度算法運(yùn)行結(jié)果