作业调度实验报告Word格式.docx

上传人:b****4 文档编号:7767739 上传时间:2023-05-09 格式:DOCX 页数:23 大小:29.06KB
下载 相关 举报
作业调度实验报告Word格式.docx_第1页
第1页 / 共23页
作业调度实验报告Word格式.docx_第2页
第2页 / 共23页
作业调度实验报告Word格式.docx_第3页
第3页 / 共23页
作业调度实验报告Word格式.docx_第4页
第4页 / 共23页
作业调度实验报告Word格式.docx_第5页
第5页 / 共23页
作业调度实验报告Word格式.docx_第6页
第6页 / 共23页
作业调度实验报告Word格式.docx_第7页
第7页 / 共23页
作业调度实验报告Word格式.docx_第8页
第8页 / 共23页
作业调度实验报告Word格式.docx_第9页
第9页 / 共23页
作业调度实验报告Word格式.docx_第10页
第10页 / 共23页
作业调度实验报告Word格式.docx_第11页
第11页 / 共23页
作业调度实验报告Word格式.docx_第12页
第12页 / 共23页
作业调度实验报告Word格式.docx_第13页
第13页 / 共23页
作业调度实验报告Word格式.docx_第14页
第14页 / 共23页
作业调度实验报告Word格式.docx_第15页
第15页 / 共23页
作业调度实验报告Word格式.docx_第16页
第16页 / 共23页
作业调度实验报告Word格式.docx_第17页
第17页 / 共23页
作业调度实验报告Word格式.docx_第18页
第18页 / 共23页
作业调度实验报告Word格式.docx_第19页
第19页 / 共23页
作业调度实验报告Word格式.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

作业调度实验报告Word格式.docx

《作业调度实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《作业调度实验报告Word格式.docx(23页珍藏版)》请在冰点文库上搜索。

作业调度实验报告Word格式.docx

#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->

<

二>

多道处理系统作业调度

1)多道处理程序作业调度实验的源程序:

duodao.c

duodao.exe

采用多道程序设计方法的操作系统,在系统中要经常保留多个运行的作业,以提高系统效率。

作业调度从系统已接纳的暂存在输入井中的一批作业中挑选出若干个可运行的作业,并为这些被选中的作业分配所需的系统资源。

对被选中运行的作业必须按照它们各自的作业说明书规定的步骤进行控制。

采用先来先服务算法算法模拟设计作业调度程序。

(1)、作业调度程序负责从输入井选择若干个作业进入主存,为它们分配必要的资源,当它们能够被进程调度选中时,就可占用处理器运行。

作业调度选择一个作业的必要条件是系统中现有的尚未分配的资源可满足该作业的资源要求。

但有时系统中现有的尚未分配的资源既可满足某个作业的要求也可满足其它一些作业的要求,那么,作业调度必须按一定的算法在这些作业中作出选择。

先来先服务算法是按照作业进入输入井的先后次序来挑选作业,先进入输入井的作业优先被挑选,当系统中现有的尚未分配的资源不能满足先进入输入井的作业时,那么顺序挑选后面的作业。

(2)假定某系统可供用户使用的主存空间共100k,并有5台磁带机。

#include<

#definegetpch(type)(type*)malloc(sizeof(type))

intj=0;

intn,i;

//n为需要输入的作业数量

//初始化周转时间,带权周转时间.

//初始化开始运行时间

intfreesa=100,disksa=5;

//预定内存的大小为100k,磁带数量为5个.

structjcb//作业控制块

charusername[10];

//用户名

intruntime;

//已经运行了的时间

intfrees;

//作业要占用的内存

intdisks;

//作业所需磁带

}*ready=NULL,*start=NULL,*p,*q,*r,*s,*t;

voidinital()//建立作业控制块队列,先将其排成先来先服务的模式队列

\n输入用户名:

username);

输入作业名:

输入作业运行要占用的内存:

frees);

输入作业运行所需磁带:

disks);

runtime=0;

if(ready==NULL)ready=q=p;

//先将其按到达的先后顺序排成后备序列

intspace()//计算内存中作业的个数

intl=0;

JCB*pr=start;

while(pr!

=NULL)

l++;

pr=pr->

return(l);

voidapply()//把符合条件的作业调用内存,并给他们分配资源,

intlen;

while(p!

frees<

=freesa&

disks<

=disksa)

freesa-=p->

frees;

disksa-=p->

disks;

r=p;

if(r==ready)//先将符合条件的作业从队列中分离出来

ready=r->

r->

=r)q=q->

next=r->

if(start==NULL)start=s=r;

//将其插到start队列,

s->

next=r;

s=r;

len=space();

\n\t此时有%d道作业在内存\n\n"

len);

voiddisp(JCB*pr)/*建立作业显示函数*/

|%s\t"

pr->

|%c\t"

state);

|%d\t"

runtime);

voidcheck()//显示作业状况

\n作业%s于完成%d个作业后运行完毕,其完成后的情况:

name,j);

j++;

\n用户名****作业名****状态****到达时间*需运行时间*已运行时间*需占用内存*需磁带数量\n"

disp(q);

s=start;

\n\t\t*********当前进入内存的作业状态*********"

while(s!

disp(s);

s=s->

r=ready;

*\n\n\t\t*********当前后备作业表中作业的状态**********"

while(r!

disp(r);

r=r->

voidrunning()//运行作业

for(t=start;

t!

=NULL;

start=t->

q=t;

runtime++;

t=start;

if(q->

runtime==q->

needtime)

finishtime=times;

starttime=q->

finishtime-q->

cycletime=q->

reachtime;

cltime=(q->

cycletime)/(q->

T1+=q->

T2+=q->

freesa+=q->

disksa+=q->

check();

//调用check()显示正在运行的,就绪的以及后备的作业信息

free(q);

//释放作业

apply();

//分配作业

for(s=start;

s->

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 党团建设

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2