磁盘驱动调度算法的模拟Word格式.docx
《磁盘驱动调度算法的模拟Word格式.docx》由会员分享,可在线阅读,更多相关《磁盘驱动调度算法的模拟Word格式.docx(13页珍藏版)》请在冰豆网上搜索。
该算法与扫描算法的区别是,回来过
程不处理请求,基于这样的事实,因为里端刚被处理。
2.设计方法
1)使用流程图描述演示程序的设计思想;
2)选取C/C++、Java等计算机语言,编程调试,最终给出运行正确的程序
3.程序步骤
参考程序:
1)C/C++版的驱动调度算法-电梯调度模拟程序#include<
stdio.h>
#inelude<
stdlib.h>
}PROC;
PROC*g_head=NULL,*g_curr=NULL,*local;
intrecord=0;
intyi=1;
voidinit()
{
/*初
PROC*p;
始化链表(初始I/O表)*/
g_head=(PROC*)malloc(sizeof(PROC));
g_head->
next=NULL;
g_head->
prior=NULL;
p=(PROC*)malloc(sizeof(PROC));
strcpy(p->
name,"
P1"
);
p->
team=100;
ci=10;
rec=1;
next=NULL;
prior=g_head;
next=p;
g_curr=g_head->
next;
P2"
p->
team=30;
ci=5;
rec=5;
prior=g_curr;
g_curr->
g_curr=p;
P3"
team=40;
ci=2;
rec=4;
P4"
team=85;
ci=7;
rec=3;
g_curr->
name,"
P5"
team=60;
ci=8;
/*选中进程*/
/*打印I/O表*/
g_curr=g_head->
local=(PROC*)malloc(sizeof(PROC));
strcpy(local->
PO"
local->
team=0;
ci=0;
rec=0;
next=NULL;
prior=NULL;
}
voidPrintlnit()
PROC*t=g_head->
next;
printf("
/n"
I/OLIST/n"
printf("
processteamcirec/n"
while(t!
=NULL)
%4s%8d%8d%5d/n"
t->
name,t->
team,t->
ci,t->
rec);
t=t->
/n/nCurrentprocessis:
/n”);
/n/n"
local-〉name,local->
team,local->
ci,local->
switch(yi)
case1:
{printf("
currentdirectionisUP/n"
break;
case0:
currentdirectionisdown/n"
);
voidacceptreq()/*接受请求函数*/
pleaseinputtheinformationofthenew
process/nprocess-name:
/nprocess-team/nprocess-ci/nprocess-rec/n"
1.name/n”);
scanf("
%s"
p->
name);
2.team0-199/n"
scanf("
%d"
&
team);
/*输入请求进程信息*/
3.ci0-19/n"
ci);
4.rec0-7/n"
rec);
getchar();
g_curr=g_head;
/*将此节点链入I/O请求表
*/
while(g_curr->
next!
=NULL)g_curr=g_curr->
next=NULL;
prior=g_curr;
next=p;
NEWI/OLIST/n/n"
Printlnit();
voidqddd()
{PROC*out;
intmin;
intmax=g_head->
next->
team;
if(g_head->
next==NULL);
else{switch(yi)
/*将新的I/O请求表输出*/
/*驱动调度函数*/
/*若已全部调度,则空操作*/
{case1:
min=g_head->
out=g_head->
team进程,模拟启动此进程*/
/*选出最小的
name,out->
team=out->
ci=out->
ci;
rec=out->
rec;
for(g_curr=g_head->
g_curr!
=NULL;
g_curr=g_curr->
next)
if(g_curr->
team>
record)
{min=g_curr->
if(min>
=g_curr->
team&
&
g_curr->
team>
record)
min=g_curr->
out=g_curr;
/n/n"
theprocesschoosed:
/n"
out->
name,out->
team,out->
ci,out->
record=local->
record);
if(max<
team)
max=g_curr->
if(max==record)
yi=0;
record=1000;
/*case1的对称过程
}/*case1*/
team<
{max=g_curr->
team<
min=g_head->
if(min>
g_curr->
if(min==record)
yi=1;
record=0;
default:
return-1;
/*将选中的进程从I/O
}/*switch*/
if(out->
next==NULL)
请求表中删除*/
out->
prior->
free(out);
}else
next=out->
out->
prior=out->
prior;
}/*else*/
voidacceptnum()/*通过输入OT选
择‘驱动调度’或是‘接受请求’*/
floatnum;
charc;
while
(1)
pleaseinputanumberbetween0and1/nnum<
=0.5:
acceptrequest/nnum>
0.5:
qudongdiaodu/n/nnum==2:
1/0LIST/n/nnum=?
scanf("
%f"
num);
while((num<
0||num>
1)&
num!
=2)/*过滤不合法数
据注意:
本程序其他输入数据可能未过滤*/
numberERROR!
Inputagainplease!
/nnum=?
/n"
if(num>
0.5&
num!
=2)
if(g_head->
next==NULL)
/n/n"
I/Olistisempty!
!
}
else
/*驱动调度*/
/*请求表为空无需调度*/
qudongdiaodu/n"
qddd();
/*通过输入2显示当前
elseif(num<
=0.5)
acceptrequest/n/n"
acceptreq();
elseif(num==2)
请求I/O表*/
I/OLIST;
"
/*输入
choose'
n'
toquitelsetocontinue/n"
n离开本程序*/
if(strcmp(c=getchar(),'
n'
)==O||strcmp(c=getchar(),'
N'
)==O)
clrscr();
/n/n/n/n/n/n"
thankyoufortestingmyprogram!
---by01/n"
sleep
(2);
/n/nBYEbye!
return-1;
main()/*主程序*/
init();
acceptnum();
设计体会
能够将磁盘驱动调度算法在各种情况下都能得出正确的结论。
对FIFO、最短寻找时间优先
或电梯调度算法能够在多次模拟数据下得出平均移动柱面数,并进行效率比较分析。
2011-2012学年第一学期
操作系统
课程设计报告
班级
学号
姓名
成绩
指导教师于复兴