实验报告六磁盘调度算法Word格式.docx
- 文档编号:7177468
- 上传时间:2023-05-08
- 格式:DOCX
- 页数:12
- 大小:26.95KB
实验报告六磁盘调度算法Word格式.docx
《实验报告六磁盘调度算法Word格式.docx》由会员分享,可在线阅读,更多相关《实验报告六磁盘调度算法Word格式.docx(12页珍藏版)》请在冰点文库上搜索。
移动方向,并且可能会发生进程饥饿现象。
电梯调度:
总是将一个方向上的请求全部处
理完后,才改变方向继续处理其他请求。
扫描(双向扫描):
总是从最外向最里进行扫描,然后在从最里向最外扫描。
该算法与电梯调度算法的区别是电梯调度在没有最外或
最里的请求时不会移动到最外或最里柱面,二扫描算法总是移到最外、最里柱面。
两端的请求有优先服被务的迹象。
循环扫描(单
向扫描):
从最外向最里进行柱面请求处理,到最里柱面后,直接跳到最外柱面然后继续向里进行处理。
该算法与扫描算法的区别是
,回来过程不处理请求,基于这样的事实,因为里端刚被处理。
2.实验方法
1)使用流程图描述演示程序的设计思想;
2)选取C/C++、Java等计算机语言,编程调试,最终给出运行正确的程序。
四.实验结果分析能够将磁盘驱动调度算法在各种情况下都能得出正确的结论。
最短寻找时间优先或电梯调度算法能够在多次模拟数据下得出平均移动柱面数,并进行效率比较分析
对FIFO、
五.源程序代码
#include<
stdio.h>
stdlib.h>
string.h>
conio.h>
typedefstruct_proc{
charname[32];
intteam;
intci;
intrec;
struct_proc*prior;
struct_proc*next;
}
/*定义进程名称*/
/*定义柱面号*/
/*定义磁道面号*/
/*定义记录号*/
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;
prior=NULL;
p=(PROC*)malloc(sizeof(PROC));
strcpy(p->
name,"
P1"
);
p->
team=100;
p->
ci=10;
rec=1;
prior=g_head;
next=p;
g_curr=g_head->
next;
p=(PROC*)malloc(sizeof(PROC));
P2"
team=30;
ci=5;
rec=5;
/*初始化
prior=g_curr;
g_curr->
g_curr=p;
P3"
team=40;
ci=2;
rec=4;
g_curr=p;
P4"
team=85;
ci=7;
rec=3;
P5"
team=60;
ci=8;
/*选中进程*/
local=(PROC*)malloc(sizeof(PROC));
strcpy(local->
P0"
local->
team=0;
local->
ci=0;
rec=0;
}
voidPrintInit()
next=NULL;
prior=NULL;
/*打印I/O表*/
PROC*t=g_head->
printf("
\n"
I/OLIST\n"
processteamcirec\n"
while(t!
=NULL)
%4s%8d%8d%5d\n"
t->
name,t->
team,t->
ci,t->
rec);
t=t->
\n\nCurrentprocessis:
\n"
printf("
\n\n"
ci,local->
down\n"
voidacceptreq()
local->
name,local->
team,switch(yi)
case1:
currentdirectionisUP\n"
break;
case0:
{printf("
currentdirectionis
break;
/*接受请求函数*/
process\nprocess-name:
\nprocess-team\nprocess-ci\nprocess-rec\n"
1.name\n"
scanf("
%s"
p->
name);
2.team0-199\n"
%d"
&
team);
/*输入请求进程信息*/printf("
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->
prior=g_curr;
g_curr->
next=p;
g_curr=g_head->
NEWI/OLIST\n\n"
PrintInit();
/*将新的I/O请求表输出*/}voidqddd()/*驱动调度函数*/
PROC*out;
intmax=g_head->
next->
team;
if(g_head->
next==NULL);
else
intmin;
/*若已全部调度,则空操作*/
switch(yi)
min=g_head->
out=g_head->
/*选
strcpy(local->
name,out->
team=out->
ci=out->
ci;
rec=out->
rec;
if(g_curr->
team>
record)
for(g_curr=g_head->
g_curr!
=NULL;
g_curr=g_curr->
next)
min
for
(g_curr=g_head->
if
(min>
=g_curr->
team&
&
team>
record)
min=g_curr->
out=g_curr;
\n\n"
choosed:
teamcirec\n"
theprocess
process
out->
name,out->
team,out->
ci,out->
(max<
team)max=g_curr->
if(max==record)
yi=0;
record=1000;
record=local->
record);
/*case1的对称过程*/
max=g_head->
}/*case1*/
out=g_head->
{if(g_curr->
team<
max=g_curr->
}for(g_curr=g_head->
if(max<
team<
max=g_curr->
theprocesschoosed:
if(min>
team)min=g_curr->
if(min==record)
yi=1;
record=0;
}/*switch*/if
/*将选中的进程从I/O请求表中删除*/
free(out);
out->
prior->
next=out->
prior=out->
prior;
}/*else*/
}default:
return-1;
(out->
next==NULL)
else
0~1选择‘驱动调度'
或是‘接
voidacceptnum()/*通过输入
受请求'
*/{
floatnum;
charc;
while
(1){
pleaseinputanumberbetween0and1\nnum<
=0.5:
acceptrequest\nnum>
0.5:
qudongdiaodu\n\nnum==2:
I/OLIST\n\nnum=?
%f"
num);
getchar();
while((num<
0||num>
1)&
num!
=2)/*过滤不合法数据注意:
本程序其他输入数据可能未过滤*/
numberERROR!
Inputagainplease!
\nnum=?
\n"
if(num>
0.5&
=2)/*驱动调度*/
if(g_head->
next==NULL){
\n\n"
I/Olistisempty!
!
/*请求表为空无需调度*/
}else
qudongdiaodu\n"
qddd();
/*调用函数进行调度*/
elseif(num<
=0.5)/*接受请求*/
accept
request\n\n"
acceptreq();
elseif(num==2)
/*通过输入2显示当前请求I/O表*/
I/OLIST;
"
PrintInit();
离开本程序*/
choose'
n'
toquitelsetocontinue\n"
/*输入if(strcmp(c=getchar(),'
)==0||strcmp(c=getchar(),'
N'
)==0)clrscr();
\n\n\n\n\n\n"
thankyoufortestingmyprogram!
---by01\n"
sleep
(2);
\n\nBYEbye!
return-1;
clrscr();
/*主程序*/
main()
init();
acceptnum();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 报告 磁盘 调度 算法