1、stdio.h#include stdlib.hconio.hiostream.h#define P_NUM 5#define P_TIME 50enum state ready, execute, block, finish;struct pcb char name4; int priority; int cputime; int needtime; int count; int round; state process; pcb * next;pcb * get_process();pcb * get_process() pcb *q; pcb *t; pcb *p; int i=0; c
2、outinput name and timeendl; while (iq-name;needtime; q-cputime=0;priority=P_TIME-q-process=ready;next=NULL; if (i=0) p=q; t=q; else t-next=q; i+; /while return p;void display(pcb *p)name cputimeneedtimeprioritystate while(p) cout;cputime;priority; switch(p-process) case ready:coutnext; int process_f
3、inish(pcb *q) int bl=1; while(bl&q) bl=bl&needtime=0; q=q- return bl;void cpuexe(pcb *q) pcb *t=q; int tp=0; while(q) if (q-process!=finish) q- if(q-needtime=0) q-process=finish; if(tp if(t-needtime!=0) t-priority-=3;needtime-;process=execute;cputime+;void priority_cal() pcb * p; p=get_process(); in
4、t cpu=0; while(!process_finish(p) cpu+;cputime:cpucputime+=2;needtime-=2; if(q-needtime while (t & t-process=finish); if(t=NULL) t=head; while (t-next!=k &process=finish) t=t- return t;void set_state(pcb *p) if (p- p-process=execute)void display_round(pcb *p)NAMECPUTIMENEEDTIMECOUNTROUNDSTATEcount;r
5、ound;void round_cal() pcb * r; p=get_process_round(); r=p; cpu+=2; cpu_round(r); r=get_next(r,p);cpu display_round(p); set_state(p);void main() display_menu(); int k; scanf(%d,&k); switch(k) case 1:priority_cal(); case 2:round_cal(); case 3: display_menu(); scanf(源程序优先数算法运行得到的结果:源程序轮转算法运行得到的结果:程序修改后
6、,优先数算法中,优先级为200,时间片为24,在轮转算法中,固定时间片为24:根据学号进行程序修改后程序运行图:程序修改内容对比: 修改后 修改后 修改前结论:通过本次验证性实验,让我理解了操作系统在运行多个进程时,是如何进行调度的,如何运用时间片与优先级来控制进程运行一次所花的时间和多个程序并行时应该先运行哪个程序。当然在实验中也遇到了许多问题,比如初次改程序之后,程序执行完之后没有变成finish以及进程每运行一次后所需时间并不是减小24等。.最终我仔细观察程序,找到应该修改finish的地方,添加语句t-process=finish程序执行完之后能输出finish,修改所需时间q-needtime-=24,使进程每执行一次后所需时间的大小都会减小24。指导教师批阅及成绩:指导老师签名:李芳 2014年 5月 10日
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1