《2022年最高优先数优先”调度算法可用 .pdf》由会员分享,可在线阅读,更多相关《2022年最高优先数优先”调度算法可用 .pdf(7页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、实验要求:编写并调试一个模拟的进程调度程序,采用“最高优先数优先”调度算法对五个进程进行调度设计思想:“最高优先数优先”调度算法的基本思想是把cpu分配给就绪队列中优先数最高的进程。采用动态优先数,即优先数在创建进程时给定一个初始值,当进程获得一次 cpu后其优先数就减少1。名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 7 页 -源程序如下:#include stdio.h#define getpcb(type)(type*)malloc(sizeof(type)#define NULL 0 struct pcb char name10;char state;int super
2、;int ntime;int rtime;struct pcb*link;*ready=NULL,*p;typedef struct pcb PCB;main()int len,h=0;char c;input();len=space();while(len!=0)&(ready!=NULL)名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 7 页 -c=getchar();h+;printf(nthe execute number:%dn,h);p=ready;ready=p-link;p-link=NULL;p-state=R;check();running();printf(
3、npress any key to continue.);c=getchar();printf(nn the process has been finished.n);c=getchar();input()int i,num;char k;名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 7 页 -clrscr();printf(ninput process number?);scanf(%d,&num);for(i=0;iname);printf(nthe super of Process:);scanf(%d,&p-super);printf(nthe time need:);
4、scanf(%d,&p-ntime);printf(n);p-rtime=0;p-state=W;p-link=NULL;sort();int space()名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 7 页 -int l=0;PCB*pr=ready;while(pr!=NULL)l+;pr=pr-link;return(l);check()PCB*pr;printf(n*Now the process running is:%s,p-name);disp(p);pr=ready;printf(n*Now the ready quenue is:n);while(pr!=N
5、ULL)disp(pr);pr=pr-link;名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 7 页 -disp(pr)PCB*pr;printf(nqnametstatetsupertdtimetruntimen);printf(%st,pr-name);printf(%ct,pr-state);printf(%dt,pr-super);printf(%dt,pr-ntime);printf(%dt,pr-rtime);printf(n);destory()printf(nprocess%s has finished:n,p-name);free(p);名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 7 页 -名师资料总结-精品资料欢迎下载-名师精心整理-第 7 页,共 7 页 -