操作系统-进程调度实验

上传人:101****457 文档编号:99941764 上传时间:2019-09-21 格式:DOCX 页数:21 大小:387.06KB
返回 下载 相关 举报
操作系统-进程调度实验_第1页
第1页 / 共21页
操作系统-进程调度实验_第2页
第2页 / 共21页
操作系统-进程调度实验_第3页
第3页 / 共21页
操作系统-进程调度实验_第4页
第4页 / 共21页
操作系统-进程调度实验_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《操作系统-进程调度实验》由会员分享,可在线阅读,更多相关《操作系统-进程调度实验(21页珍藏版)》请在金锄头文库上搜索。

1、实验五 进程调度模拟实验/进程调度算法proc.c#include #include#include typedef struct pcb/定义PCB结构char name20; /*进程标识符*/int cputime; /*进程占用CPU时间*/int prio; /*进程优先数*/int needtime; /*进程到完成还需要的CPU时间*/struct pcb *next;/*链指针*/PCB;PCB *RUN,*READY,*RTAIL,*FINSH,*FTAIL;void PRINTLINK(int t)/*输出3个队列*/PCB *p;printf(CPU运行次数:_%d_n,

2、t);printf(_n);printf(进程名t运行状态t运行次数t还需要运行次数n);if(RUN!=NULL) printf(%st运行t%dt%dn,RUN-name,RUN-cputime,RUN-needtime); else printf(*运行状态为空n);p=READY;if(p!=NULL) while(p!=NULL) printf(%st就绪t%dt%dn,p-name,p-cputime,p-needtime); p=p-next; else printf(*就绪队列为空n);p=FINSH;if (p!=NULL) while(p!=NULL)/printf( 进程

3、名字为:%sn,p-name);printf(%st完成t%dt%dn,p-name,p-cputime,p-needtime);p=p-next;elseprintf(*完成队列为空n);getchar();PCB *CPCBLINK()/*建立就绪队列*/ printf(建立就绪队列nn);int i,n,nt,pr;PCB *p,*q,*head;n=0;while(1) printf(请输入进程的个数(有效范围1-100):); scanf(%d,&n); printf(n); if (n=1&nname);while(1) printf(需要的运行时间:); scanf(%d,&nt

4、); if(nt0) break; else printf(输入无效,重新输入!n); getchar(); head-needtime=nt;printf(优先数:);scanf(%d,&pr);head-prio=pr; head-cputime=0;/*进程已获得的运行时间*/head-next=NULL;q=head; for(i=1;iname); printf(需要的运行时间:); scanf(%d,&nt); p-needtime=nt; printf(优先数:); scanf(%d,&pr); p-prio=pr;p-cputime=0;/*进程已获得的运行时间*/ p-nex

5、t=NULL;q-next=p;q=p; RTAIL=q;return head;void JXDLPX()/*就绪队列按优先级从大到小排序*/ PCB *p,*q,*t; char s10; int L=0,ct,pr,nt; p=READY; t=(struct pcb* )malloc(sizeof(struct pcb); while(p-next!=NULL) L=0; q=p-next; t=p; while(q!=NULL) if(t-prioprio) t=q; L=1;/*表示有比它优先级大的进程*/ q=q-next; if(L=1) strcpy(s,t-name); c

6、t=t-cputime; pr=t-prio; nt=t-needtime; q=p-next; while(strcmp(q-name,s)!=0) q=q-next; strcpy(q-name,p-name); q-cputime=p-cputime; q-prio=p-prio; q-needtime=p-needtime; strcpy(p-name,s); p-cputime=ct; p-prio=pr; p-needtime=nt; p=p-next; void YXS()/*调用优先数调度算法*/PCB *p;int t=0,nt,ct,pr;printf(您选择的是:优先级调

7、度算法n);READY=CPCBLINK();/*建立就绪队列*/p=(struct pcb* )malloc(sizeof(struct pcb);while(READY!=NULL) JXDLPX();/*就绪队列按优先级从大到小排序*/ p=READY; READY=READY-next; p-next=NULL; pr=p-prio; pr=pr-3; p-prio=pr;/*运行1次进程优先级缩小3*/ nt= p-needtime; nt=nt-1; p-needtime=nt; ct=p-cputime; ct=ct+1; p-cputime=ct; RUN=p; PRINTLI

8、NK(t);/*输出3个队列*/ if( RUN-needtimenext=p; FTAIL=FTAIL-next; RUN=NULL; else /*若运行没结束进入就绪队列*/ if (READY=NULL)/*当就绪队列为空*/ READY=p; RTAIL=p; else RTAIL-next=p; RTAIL=p; RUN=NULL; t+;void SJP()/*调用时间片循环轮转算法*/PCB *p;printf(您选择的是:时间片循环轮转调度算法n); int t=0,nt,ct;READY=CPCBLINK();/*建立就绪队列*/p=(struct pcb* )malloc

9、(sizeof(struct pcb);while(READY!=NULL) p=READY; READY=READY-next; p-next=NULL; nt= p-needtime; nt=nt-2; if(ntneedtime=nt; ct=p-cputime; ct=ct+2; p-cputime=ct; RUN=p; PRINTLINK(t);/*输出3个队列*/ if( RUN-needtimenext=p; FTAIL=FTAIL-next; RUN=NULL; else/*若运行没结束进入就绪队列*/ if (READY=NULL)/*当就绪队列为空*/ READY=p; RTAIL=p; else RTAIL-next=p; RTAIL=p; RUN=NULL; t+;/*主程序*/int main() int N;RUN=(struct pcb* )malloc(sizeof(struct pcb); while(1)RUN =NULL; READY =NULL; RTAIL=NULL; FINSH=NULL; FTAIL=NULL;printf(=

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号