




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 操作系统实验(2) 实验题目:作 业 调 度 实 验课程名称:操 作 系 统 学 院: 专业班级: 学 号(1): 姓 名(1): 学 号(2): 姓 名(2): 任课教师: 2010年4月12日学院:管 理 学 院 班级: 组员: 组员: 评定: 实验题目:作业调度实验(1) 实验目的:用高级语言编写和调试一个或多个作业调度的模拟程序,以加深对作业调度算法的理解。(2)实验内容:编写并调试一个单道处理系统的作业等待模拟程序。作业等待算法:分别采用先来先服务(fcfs),最短作业优先(sjf)、响应比高者优先(hrn)的调度算法。对每种调度算法都要求打印每个作业开始运行时刻、完成时刻、周转时
2、间、带权周转时间,以及这组作业的平均周转时间及带权平均周转时间,以比较各种算法的优缺点。(3) 源代码(含注释):先来先服务(fcfs):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define null 0 struct jcb /* 定义作业控制块pcb */ char name10; char state; int ttime; int ntime; int rtime; int otime; int etime; float zztime; float dqtim
3、e; struct jcb* link; *ready=null,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb jcb; void sort() /* 建立对进程进行提交时间排列函数*/ jcb *first, *second; int insert=0; if(ready=null)|(p-ttime)ttime) /*提交时间最大者,插入队首*/ p-link=ready; ready=p; else /* 进程比较提交时间,插入适当的位置中*/ first=ready;
4、 second=first-link; while(second!=null) if(p-ttime)ttime) /*若插入进程比当前提交时间早*/ /*插入到当前进程前面*/ p-link=second; first-link=p; second=null; insert=1; else /* 插入进程提交时间最晚,则插入到队尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() jcb *pr; pr=ready; if(p-link!=null) if(ready-ttimelink!
5、=null) pr=pr-link; pr-link=p; p-link=null; p=ready; ready=p-link; else ready=p; void input() /* 建立进程控制块函数*/ int i; clrscr(); /*清屏*/ printf(n input the number of process?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime nee
6、d to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w; p-link=null; sort(); /* 调用sort函数*/ void disp(jcb * pr) /*建立进程显示函数,用于显示当前进程*/ printf(n qname t state t ndtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check()
7、/* 建立进程查看函数 */ jcb* pr; printf(n * now the running process is:%s,p-name); /*显示当前运行进程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*显示就绪队列状态*/ while(pr!=null)&(p-link!=null) if(pr-ttimelink; void destroy() /*建立进程撤消函数(进程运行结束,撤消进程)*/ num-; p-etime=ertime; p-zztime=ertime
8、-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pztime+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=null)ready=null; if(ready-link!=null) p=ready; ready
9、=p-link; elsep=ready; void running() /* 建立进程就绪函数(进程运行时间到,置就绪状态)*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) destroy(); /* 调用destroy函数*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函数*/ int h=0; char
10、 ch; input(); p=ready; ready=p-link; while(num!=0)&(ready!=null) ch=getchar(); h+; printf(n the execute number:%d n,h); p-state=r; running(); printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround t
11、ime is %-3.1f,the average turnaround time with right is %-3.1fn,pztime,pqtime); ch=getchar(); 最短作业优先(sjf):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define null 0 struct jcb /* 定义作业控制块pcb */ char name10; char state; int ttime; int ntime; int rtime; int otime;
12、 int etime; float zztime; float dqtime; struct jcb* link; *ready=null,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb jcb; void sort() /* 建立对进程进行提交时间排列函数*/ jcb *first, *second; int insert=0; if(ready=null)|(p-ttime)ttime) /*提交时间最大者,插入队首*/ p-link=ready; ready=p; els
13、e /* 进程比较提交时间,插入适当的位置中*/ first=ready; second=first-link; while(second!=null) if(p-ttime)ttime) /*若插入进程比当前提交时间早*/ /*插入到当前进程前面*/ p-link=second; first-link=p; second=null; insert=1; else /* 插入进程提交时间最晚,则插入到队尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() jcb *pr1,*pr2,*prx
14、,*pry; float x,y; prx=p; pry=prx-link; x=(srtime-p-otime)+(p-ntime); y=x/p-ntime; if(p-link!=null) while(pry!=null) if(yntime-pry-rtime) y=pry-ntime-pry-rtime;pr1=prx;pr2=pry; prx=prx-link;pry=prx-link; if(prx!=p&pr2-ttimelink=pr2-link;pr2-link=p;p=pr2;ready=p-link; else ready=p; void input() /* 建立进
15、程控制块函数*/ int i; clrscr(); /*清屏*/ printf(n input the number of process?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime need to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w;p-otime=0; p-link=null; sort(); /* 调
16、用sort函数*/ void disp(jcb * pr) /*建立进程显示函数,用于显示当前进程*/ printf(n qname t state t ndtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check() /* 建立进程查看函数 */ jcb* pr; p-otime=srtime; printf(n * now the running process is:%s,p-name);
17、 /*显示当前运行进程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*显示就绪队列状态*/ while(pr!=null)&(p-link!=null) if(pr-ttimestate=w; disp(pr); pr=pr-link; void destroy() /*建立进程撤消函数(进程运行结束,撤消进程)*/ num-; p-etime=ertime; p-zztime=ertime-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pzti
18、me+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=null) ready=null;if(ready-link!=null) p=ready; ready=p-link; elsep=ready; void running() /* 建立进程就绪函数
19、(进程运行时间到,置就绪状态)*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) destroy(); /* 调用destroy函数*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函数*/ int h=0; char ch; input(); p=ready; ready=p-link; while(num!=
20、0)&(ready!=null) ch=getchar(); h+; printf(n the execute number:%d n,h); p-state=r; running(); printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround time is %-3.1f,the average turnaround time with r
21、ight is %-3.1fn,pztime,pqtime); ch=getchar(); 响应比高者优先(hrn):#include stdio.h #include #include #define getpch(type) (type*)malloc(sizeof(type) #define null 0 struct jcb /* 定义作业控制块pcb */ char name10; char state; int ttime; int ntime; int rtime; int otime; int etime; float zztime; float dqtime; struct
22、jcb* link; *ready=null,*p;int num,n;int srtime=0,ertime=1;float pztime=0.0,pqtime=0.0; typedef struct jcb jcb; void sort() /* 建立对进程进行提交时间排列函数*/ jcb *first, *second; int insert=0; if(ready=null)|(p-ttime)ttime) /*提交时间最大者,插入队首*/ p-link=ready; ready=p; else /* 进程比较提交时间,插入适当的位置中*/ first=ready; second=fi
23、rst-link; while(second!=null) if(p-ttime)ttime) /*若插入进程比当前提交时间早*/ /*插入到当前进程前面*/ p-link=second; first-link=p; second=null; insert=1; else /* 插入进程提交时间最晚,则插入到队尾*/ first=first-link; second=second-link; if(insert=0) first-link=p; void pl() jcb *pr1,*pr2,*prx,*pry; int x; prx=p; pry=prx-link; x=(p-ntime)-
24、(p-rtime); if(p-link!=null) while(pry!=null) if(xpry-ntime-pry-rtime) x=pry-ntime-pry-rtime;pr1=prx;pr2=pry; prx=prx-link;pry=prx-link; if(prx!=p&pr2-ttimelink=pr2-link;pr2-link=p;p=pr2;ready=p-link; else ready=p;void input() /* 建立进程控制块函数*/ int i; clrscr(); /*清屏*/ printf(n input the number of proces
25、s?); scanf(%d,&num); n=num; for(i=0;iname); printf(n input the submit time :); scanf(%d,&p-ttime); printf(n input the processtime need to run:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-state=w; p-link=null; sort(); /* 调用sort函数*/ void disp(jcb * pr) /*建立进程显示函数,用于显示当前进程*/ printf(n qname t state t n
26、dtime t runtime t ttime n ); printf(|%st,pr-name); printf(|%ct,pr-state); printf(|%dt,pr-ntime); printf(|%dt,pr-rtime); void check() /* 建立进程查看函数 */ jcb* pr; printf(n * now the running process is:%s,p-name); /*显示当前运行进程*/ disp(p); printf(|%dt,p-ttime); pr=ready; printf(n *the ready team are:n); /*显示就绪
27、队列状态*/ while(pr!=null)&(p-link!=null) if(pr-ttimestate=w; disp(pr); pr=pr-link; void destroy() /*建立进程撤消函数(进程运行结束,撤消进程)*/ num-; p-etime=ertime; p-zztime=ertime-p-ttime; p-dqtime=p-zztime/p-ntime; pztime=pztime+p-zztime; pqtime=pqtime+p-dqtime; printf(n process %s have been achieved.n,p-name); printf(
28、turnaround time is %-3.1f,turnaround time with the right is %-3.1f,p-zztime,p-dqtime); free(p); if(p-link=null)ready=null; if(ready-link!=null) p=ready; ready=p-link; elsep=ready; void running() /* 建立进程就绪函数(进程运行时间到,置就绪状态)*/ if(p-ttimertime)+; check(); srtime+; ertime+; pl(); if(p-rtime=p-ntime) dest
29、roy(); /* 调用destroy函数*/ else p-state=w; else printf(the process isnt come into merroy,wait the next time); srtime+; ertime+; void main() /*主函数*/ int h=0; char ch; input(); p=ready; ready=p-link; while(num!=0)&(ready!=null) ch=getchar(); h+; printf(n the execute number:%d n,h); p-state=r; running();
30、printf(n press any key to continue.); ch=getchar(); pztime=pztime/n; pqtime=pqtime/n; printf(nn process have been achieved.n); printf(the average turnaround time is %-3.1f,the average turnaround time with right is %-3.1fn,pztime,pqtime); ch=getchar(); (4) 每个函数的流程图:先来先服务(fcfs):1. void sort()函数:该函数用于对
31、进程进行提交时间排列。 insert=0开始 ready是否为空或者(p-ttime)是否小于(ready-ttime)? 是 否 first=ready;second=first-link进程比较提交时间,插入适当的位置中 p-link=ready;ready=p即提交时间最大者插入队首second是否为空? 否 是(p-ttime)是否小于(second-ttime)insert是否为0 是 否 是 first=first-link second=second-link插入进程提交时间最晚,则插入到队尾first-link=pp-link=second;first-link=p secon
32、d=null;insert=1若插入进程比当前提交时间早,则插入到当前进程前面结束2. void pl()函数开始pr=readyp-link是否为空? 否 是ready-ttime是否小于等于srtimeready=p 是 否 pr-link是否为空是 pr-link=pp-link=null p=readyready=p-linkpr=pr-link结束3. void input()函数:该函数用于建立进程控制块。开始清屏输入进程数目n=numi是否小于num 是 否p=getpch(jcb)结束输入进程名、提交时间和进程所需运行时间 p-rtime=0 p-state=w;p-link=
33、null调用sort函数4. void disp(jcb * pr)函数:建立进程显示函数,用于显示当前进程。开始显示当前进程(进程名、进程状态、所需要的时间、运行时间和提交时间)结束5. void check()函数:该函数用于进程查看。开始显示当前运行进程显示就绪队列状态pr和p-link是否同时为空 否 是pr-ttime是否小于等于srtime 否 是 disp(pr)pr=pr-link结束开始6. void destroy()函数:建立进程撤消函数(进程运行结束,撤消进程)。 num- p-etime=ertime p-zztime=ertime-p-ttimep-dqtime=p
34、-zztime/p-ntime pztime=pztime+p-zztime pqtime=pqtime+p-dqtime 进程已经完成输出周转时间和带权周转时间释放pp-link是否为空? 是 否ready=nullready-link是否为空?否 是p=ready p=readyready=p-link结束7. void running()函数:建立进程就绪函数(进程运行时间到,置就绪状态)。开始p-ttime是否小于等于srtime 是 否进程未进入内存,等待下一时间(p-rtime)+ check() srtime+ ertime+调用pl()函数srtime+ertime+p-rti
35、me是否等于p-ntime?是 否p-state=w调用destroy函数结束8. 主函数开始 h=0 input() p=readyready=p-linknum是否为0且同时ready是否为空? 否 是pztime=pztime/npqtime=pqtime/n ch=getchar() h+ 进程完成输出平均周转时间和平均带权周转时间p-state=r running()按任意键继续ch=getchar()ch=getchar()结束最短作业优先(sjf):1. void sort()函数:该函数用于对进程进行提交时间排列。开始inser=0ready是否为空或者(p-ttime)是否小于(ready-ttime)? 是 否 first=ready;second=first-link进程比较提交时间,插入适当的位置中 p-link=ready;ready=p即提交时间最大者插入队首second是否为空? 否 是(p-ttime)是否小于(second-ttime)insert是否为0 是 否 是 first=first-link second=second-link插入进程提交时间最晚,则插入到队尾first-link=pp-link=second;first-link=p second=null;insert=1若插入进程比当前提交时间早,则插入到当前进程前面结束2.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 马铃薯种植园采购运输协议
- 旅游景区租赁居间协议样本
- 科技企业创新路径与投资策略研究
- 科技助力下的老年人运动能力恢复策略研究
- 主题公园室内设计合同
- 教育培训中心装饰维修协议
- 2025年加氢系列产品合作协议书
- 机械系统仿真技术在产品设计中的应用
- 神经外科手术室环境优化与感染控制
- 全国计算机等级考试一级MS Office选择题(300题)练习题库
- 网络营销讲义网络营销产品策略课件
- 《小型混凝土预制件标准化生产管理办法》
- 六年级上册英语教案-Culture 2 Going Green 第二课时 广东开心英语
- 警察叔叔是怎样破案的演示文稿课件
- 青年教师个人成长档案
- 2021译林版高中英语选择性必修三课文翻译
- 2022年华中科技大学博士研究生英语入学考试真题
- 《网店运营与管理》整本书电子教案全套教学教案
- 打印版 《固体物理教程》课后答案王矜奉
- 中考《红星照耀中国》各篇章练习题及答案(1-12)
- Q∕GDW 11612.43-2018 低压电力线高速载波通信互联互通技术规范 第4-3部分:应用层通信协议
评论
0/150
提交评论