操作系统作业调度实验报告Word文件下载.docx
- 文档编号:3646156
- 上传时间:2023-05-02
- 格式:DOCX
- 页数:18
- 大小:101.12KB
操作系统作业调度实验报告Word文件下载.docx
《操作系统作业调度实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《操作系统作业调度实验报告Word文件下载.docx(18页珍藏版)》请在冰点文库上搜索。
3、对每种调度算法都要求打印每个作业开始运行时刻、完成时刻、周转时间、带权周转时间,以及这组作业的平均周转时间及带权平均周转时间。
3)流程图:
二.最短作业优先算法
三.高响应比算法
图一.先来先服务流程图
4)源程序:
#include<
stdio.h>
#include<
stdlib.h>
conio.h>
#definegetpch(type)(type*)malloc(sizeof(type))
#defineNULL0
intn;
floatT1=0,T2=0;
inttimes=0;
structjcb//作业控制块
{
charname[10];
//作业名
intreachtime;
//作业到达时间
intstarttime;
//作业开始时间
intneedtime;
//作业需要运行的时间
floatsuper;
//作业的响应比
intfinishtime;
//作业完成时间
floatcycletime;
//作业周转时间
floatcltime;
//作业带权周转时间
charstate;
//作业状态
structjcb*next;
//结构体指针
}*ready=NULL,*p,*q;
typedefstructjcbJCB;
voidinize()//初始化界面
printf("
\n\n\t\t*********************************************\t\t\n"
);
\t\t\t\t实验二作业调度\n"
\t\t*********************************************\t\t\n"
\n\n\n\t\t\t\t\t计算机学院软件四班\n"
\t\t\t\t\t蓝小花\n"
\t\t\t\t\t3204007102\n"
\t\t\t\t\t完成日期:
2006年11月17号"
\n\n\n\t\t请输入任意键进入演示过程\n"
getch();
}
voidinital()//建立作业控制块队列,先将其排成先来先服务的模式队列
inti;
printf("
\n输入作业数:
"
scanf("
%d"
&
n);
for(i=0;
i<
n;
i++)
{
p=getpch(JCB);
\n输入作业名:
scanf("
%s"
p->
name);
p->
reachtime=i;
作业默认到达时间:
i);
\n输入作业要运行的时间:
p->
needtime);
state='
W'
;
next=NULL;
if(ready==NULL)ready=q=p;
else{
q->
next=p;
q=p;
}
voiddisp(JCB*q,intm)//显示作业运行后的周转时间及带权周转时间等
if(m==3)//显示高响应比算法调度作业后的运行情况
\n作业%s正在运行,估计其运行情况:
\n"
q->
开始运行时刻:
%d\n"
starttime);
完成时刻:
finishtime);
周转时间:
%f\n"
cycletime);
带权周转时间:
cltime);
相应比:
super);
else//显示先来先服务,最短作业优先算法调度后作业的运行情况
voidrunning(JCB*p,intm)//运行作业
if(p==ready)//先将要运行的作业从队列中分离出来
ready=p->
next;
else
q=ready;
while(q->
next!
=p)q=q->
next=p->
starttime=times;
//计算作业运行后的完成时间,周转时间等等
R'
finishtime=p->
starttime+p->
needtime;
cycletime=(float)(p->
finishtime-p->
reachtime);
cltime=(float)(p->
cycletime/p->
T1+=p->
cycletime;
T2+=p->
cltime;
disp(p,m);
//调用disp()函数,显示作业运行情况
times+=p->
F'
\n%shasbeenfinished!
\npressanykeytocontinue...\n"
free(p);
//释放运行后的作业
voidsuper()//计算队列中作业的高响应比
JCB*padv;
padv=ready;
do{
if(padv->
state=='
&
padv->
reachtime<
=times)
padv->
super=(float)(times-padv->
reachtime+padv->
needtime)/padv->
needtime
padv=padv->
}while(padv!
=NULL);
voidfinal()//最后打印作业的平均周转时间,平均带权周转时间
floats,t;
t=T1/n;
s=T2/n;
\n\n作业已经全部完成!
\n%d个作业的平均周转时间是:
%f"
n,t);
\n%d个作业的平均带权周转时间是%f:
\n\n\n"
n,s);
voidhrn(intm)//高响应比算法
JCB*min;
inti,iden;
system("
cls"
inital();
for(i=0;
p=min=ready;
iden=1;
super();
if(p->
if(iden)
min=p;
iden=0;
elseif(p->
super>
min->
super)min=p;
p=p->
}while(p!
i--;
times++;
//printf("
\ntime=%d:
\tnoJCBsubmib...wait..."
time);
if(times>
1000)
{printf("
\nruntimeistoolong...error..."
getch();
running(min,m);
//调用running()函数
}
}//for
final();
voidsjf(intm)//最短作业优先算法
if(iden){
needtime<
needtime)min=p;
=NULL);
if(iden){
i--;
//printf("
times++;
if(times>
100){printf("
\nruntimeistoolong...error"
voidfcfs(intm)//先来先服务算法
p=ready;
=times)iden=0;
if(iden)p=p->
=NULL&
iden);
\n没有满足要求的进程,需等待"
\n时间过长"
running(p,m);
voidmune()
intm;
\t\t\t\t作业调度演示\n"
\n\n\n\t\t\t1.先来先服务算法."
\n\t\t\t2.最短作业优先算法."
\n\t\t\t3.响应比高者优先算法"
\n\t\t\t0.退出程序."
\n\n\t\t\t\t选择所要操作:
m);
switch(m)
case1:
fcfs(m);
mune();
break;
case2:
sjf(m);
case3:
hrn(m);
case0:
default:
选择错误,重新选择."
}
main()//主函数
inize();
5)调试结果:
1.选择操作的界面
2.输入操作初始信息:
3.先来先服务算法作业调度结果:
(调度顺序:
a->
b->
c->
d->
e)
4.最短作业优先算法作业调度结果(调度顺序:
a->
e->
c)
5.高响应比算法作业调度结果:
(调度顺序a->
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 操作系统 作业 调度 实验 报告