编写并调试一个多道程序系统的作业调度模拟_第1页
编写并调试一个多道程序系统的作业调度模拟_第2页
编写并调试一个多道程序系统的作业调度模拟_第3页
编写并调试一个多道程序系统的作业调度模拟_第4页
编写并调试一个多道程序系统的作业调度模拟_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、编写并调试一个多道程序系统的作业调度模拟程序 五 编写并调试一个多道程序系统的作业调度模拟程序。 作业调度算法:采用基于优先级的作业调度。 可以参考课本中的例子自行设计。 #include <stdio.h>#include <stdlib.h> #define getjch(type) (type*)malloc(sizeof(type) #define N 10struct jcb /* 定义作业控制块PCB */ char name10; float needtime; /*运行时间*/float arrivetime;/*提交时刻*/float storageN

2、;/*系统资源*/struct jcb* link; *ready=NULL,*pb=NULL,*p; typedef struct jcb JCB; float Tc,Ti,Wi,T=0;/*完成时刻,周转时间,带权周转时间,时间量*/float TiSum=0,WiSum=0;/*平均周转时间,带权a平均周转时间*/float sourceN;int n;void input(); /*输入作业信息*/int space(); /* 返回就绪队列中作业的数目*/void fcfs(); /*先来先服务算法*/void disp(JCB *pr); /* 显示相应的作业*/void runn

3、ing(); /*运行作业组*/void destroy(); /* 撤销作业*/void input() /* 建立作业控制块函数*/ int i,k,num; printf("请输入所拥有的资源种类:");scanf("%d",&n);printf("输入系统所拥有资源数:n");for(i=0;i<n;i+)printf("资源%d:",i);scanf("%f",&sourcei); printf("n 输入作业数量:");scanf("

4、;%d",&num); for(i=0;i<num;i+) printf("n 作业号%d:n",i);p=getjch(JCB); printf("输入作业名:");scanf("%s",p->name); printf("输入提交时间:");scanf("%f",&p->arrivetime);printf("输入运行时间:");scanf("%f",&p->needtime); printf(

5、"输入所需资源数:n");for(k=0;k<n;k+)printf("资源%d:",i);scanf("%f",&p->storagek); printf("n"); p->link=NULL; fcfs(); int space() int l=0; JCB* pr=ready; while(pr!=NULL) l+; pr=pr->link; return(l); void disp(JCB * pr) /*建立作业显示函数,用于显示当前作业*/ int i;printf(&q

6、uot;n%6st%6st%6st","作业名","运行时间","提交时刻");for(i=0;i<n;i+)printf("资源%dt",i);printf("n%6st%6.2ftt%6.2ft",pr->name,pr->needtime,pr->arrivetime);for(i=0;i<n;i+)printf("t%6.2f",pr->storagei);printf("n"); void destr

7、oy() /*建立作业撤消函数(作业运行结束,撤消作业)*/ free(p); void check()JCB *first,*fir,*p;int flag=0,i,test=0;first=pb;while(first&&(T>=first->arrivetime)&&(flag=0)for(i=0;i<n;i+)if(sourcei>=first->storagei)sourcei=sourcei-first->storagei;elsetest=1;if(test=0)p=first;first=first->l

8、ink;p->link=NULL;if(ready=NULL)ready=p;elsefir=ready;while(fir->link!=NULL)fir=fir->link;fir->link=p;elseflag=1;pb=first;void fcfs()JCB *first,*second;int ins=0;if(pb=NULL)|(p->arrivetime<pb->arrivetime )p->link=pb;pb=p;elsefirst=pb;second=first->link;while(second!=NULL)if

9、(p->arrivetime<second->arrivetime)p->link=second;second=NULL;first->link=p;ins=1;elsefirst=first->link; second=second->link;if(ins=0)first->link=p;void running()JCB *pr;int i;printf("正在运行的作业是:%sn",p->name);disp(p);if(ready!=NULL)printf("就绪队列如下:n");pr=re

10、ady;while(pr!=NULL)disp(pr);pr=pr->link;elseprintf("就绪队列为空队列!n");if(pb!=NULL)printf("后备队列如下:n");pr=pb;while(pr!=NULL)disp(pr);pr=pr->link;elseprintf("后备队列为空队列!n");printf("作业%s的开始运行时刻T:%4.2fn",p->name,T);Tc=T+p->needtime;T=Tc;Ti=Tc-p->arrivetime;

11、Wi=Ti/(p->needtime);for(i=0;i<n;i+)sourcei=sourcei+p->storagei;printf("完成时刻Tc:%4.2fn",Tc);printf("周转时间Ti:%4.2fn",Ti);printf("带权周转时间Wi:%4.2fn",Wi);TiSum+=Ti;WiSum+=Wi;destroy();main() /主函数int len; char ch;input(); T=pb->arrivetime;check();len=space(); while(len!=0)&&(ready!=NULL) system("pause");p=ready; ready=p->link; p->link=NULL; running();if(pb!=NULL)if(ready=NULL)if(

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论