实验报告材料一进程调度算法Word下载.docx
- 文档编号:8641801
- 上传时间:2023-05-12
- 格式:DOCX
- 页数:15
- 大小:78.94KB
实验报告材料一进程调度算法Word下载.docx
《实验报告材料一进程调度算法Word下载.docx》由会员分享,可在线阅读,更多相关《实验报告材料一进程调度算法Word下载.docx(15页珍藏版)》请在冰点文库上搜索。
4、程序及运行结果(或实验数据记录及分析)
本次实验让我更加明白进程调度的概念,更加了解进程调度的工作原理。
在前期,我是直接将结果显示出来,后来,我又在原有的基础上加了显示每一时刻队列的信息。
在编写此代码过程中遇到很多问题,例如指针问题,指针指来指去,总是指错地址。
具体代码:
#include<
stdio.h>
stdlib.h>
#defineMAX1000
typedefstructprogress{
intID;
//进程名
charstate;
//进程状态
intsuper;
//优先数
intarrive_time;
//到达时间
intserve_time;
//服务时间
structprogress*next;
}node;
node*sortFCFS(node*head,node*q)
{
node*p,*pre;
intdone=0;
if((head==NULL)||((q->
arrive_time)<
(head->
arrive_time)))/*到达时间最先者,插入队首*/
{
q->
next=head;
head=q;
}
else/*进程比较到达时间,插入适当的位置中*/
p=head;
pre=p->
next;
while(pre!
=NULL)
{
if((q->
(pre->
arrive_time))/*若插入进程比当前进程到达时间小,*/
{/*插入到当前进程前面*/
q->
next=pre;
p->
next=q;
pre=NULL;
done=1;
}
else
{
p=p->
pre=pre->
}
if(done==0)p->
returnhead;
}
/*
函数功能:
创建单链表
参数:
空
返回值:
指向节点的指针head
*/
node*create()
node*head;
node*p,*q;
intx,count=0;
head=NULL;
printf("
\n\t\t请输入进程名【输入-1结束】:
"
);
while(scanf("
%d"
&
x)!
=EOF&
&
x!
=-1)
{
p=(node*)malloc(sizeof(node));
printf("
\t\t请输入优先级数【优先数高者优先】:
scanf("
%d"
p->
super);
\t\t请输入到达时间【到达时间不得小于0】:
arrive_time);
\t\t请输入服务时间【服务时间必须大于0】:
serve_time);
p->
ID=x;
state='
w'
;
next=NULL;
head=sortFCFS(head,p);
\n\t\t请输入进程名(输入-1结束):
}
输出单链表
指向节点的指针head
voidprint(node*head)
node*p;
\n\t|--------------------------结点信息情况--------------------------|"
\n\t\t|进程名|优先级数|到达时间|服务时间|状态|"
p=head;
while(p)
\n\t\t|%8d|%8d|%8d|%8d|%8c|"
p->
ID,p->
super,p->
arrive_time,p->
serve_time,p->
state);
p=p->
\n\t|--------------------------结点信息情况--------------------------|\n"
利用先来先服务调度算法
存在问题:
voidFCFS(node*head)
intstart_time,finish_time=0,round_time,all_time=0;
intdone=1;
intclock=0;
floatright_round_time;
node*p,*q,*flag;
flag=p=head;
clock=p->
arrive_time;
all_time=start_time=head->
all_time+=p->
serve_time;
while(done)
done=0;
\n\n\t|---------------------------第%2d时刻---------------------------|"
clock);
while(p)
{
if(p->
arrive_time<
=clock&
state=='
||p->
r'
)
{
done=1;
}
p=p->
}
while(flag->
next)flag=flag->
print(head);
\t|---------------------------第%2d时刻---------------------------|\n\n"
if(clock==all_time)break;
clock++;
finish_time=start_time+head->
if(finish_time==clock)
head->
f'
flag->
head=head->
flag=flag->
start_time=finish_time;
}p=head;
finish_time=p->
\t|--------------------------FCFS调度算法--------------------------|"
\n\t|进程名|到达时间|服务时间|开始时间|完成时间|周转时间|带权周转|"
if(p->
=finish_time)
else
start_time=p->
finish_time=start_time+p->
round_time=finish_time-p->
right_round_time=(float)round_time/p->
\n\t|%8d|%8d|%8d|%8d|%8d|%8d|%8.2f|"
ID,
serve_time,start_time,finish_time,round_time,right_round_time);
\n\t|--------------------------FCFS调度算法--------------------------|"
\n"
voidSortBySuper(node*head)
node*p1,*q1,*temp;
temp=(node*)malloc(sizeof(node));
for(p1=head->
p1!
=NULL&
p1->
p1=p1->
next)
for(q1=p1->
q1!
q1->
q1=q1->
if(p1->
super<
super)
temp->
ID=p1->
ID;
p1->
ID=q1->
q1->
ID=temp->
super=p1->
super;
super=q1->
super=temp->
arrive_time=p1->
arrive_time=q1->
arrive_time=temp->
serve_time=p1->
serve_time=q1->
serve_time=temp->
state=p1->
state;
state=q1->
state=temp->
利用优先数调度算法
voidpriority(node*head)
SortBySuper(head);
while(flag->
\n\t|--------------------------优先数调度算法--------------------------|"
intmain()
charchoice;
do{
\n\t\t|----------------MUNE---------------|\n"
\t\t|----------1.FCFS调度算法-----------|\n"
\t\t|----------2.优先数调度算法---------|\n"
\t\t\t你的选择是:
<
>
\b\b"
}while(scanf("
%c"
choice)!
=EOF&
choice!
='
1'
2'
head=create();
switch(choice)
case'
:
print(head);
FCFS(head);
break;
priority(head);
运行结果截图:
先来先服务调度算法运行结果
优先级调度算法运行结果
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验 报告 材料 进程 调度 算法