操作系统实验报告Word格式.docx
《操作系统实验报告Word格式.docx》由会员分享,可在线阅读,更多相关《操作系统实验报告Word格式.docx(98页珍藏版)》请在冰豆网上搜索。
实验内容:
(1)利用程序设计语言模拟分时系统中多个进程按时间片轮转调度算法进行进程调度的过程;
(2)假设有五个进程A,B,C,D,E,它们的到达时间及要求服务的时间分别为:
进程名
A
B
C
D
E
到达时间
1
2
3
4
服务时间
时间片大小为1,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。
(3)修改时间片大小为2,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。
(4)修改时间片大小为4,利用程序模拟A,B,C,D,E五个进程按时间片轮转的调度及执行过程并计算各进程的周转时间及带权周转时间。
时间片的大小对计算机的性能产生什么影响?
在时间片轮转算法中,时间片的大小对系统性能有很大的影响,如选择很小的时间片将有利于段作业,因为它能较快地完成,但会频繁地发生中断、进程上下文的切换,从而增加系统的开销,降低了CPU效率;
反之,如选择太长的时间片,使得每个进程都能在一个时间片内完成,时间片轮转算法便退化为FCFS算法,无法满足交互式用户的需求。
一个较为可取的大小是,时间片略大于一次典型的交互所需要的时间。
这样可使大多数进程在一个时间片内完成。
源代码:
#include"
stdio.h"
stdlib.h"
iostream.h"
cstdlib"
structprocess
{
charname;
intarri_time;
//arrivedtime
intserv_time;
//serveredtime
inthave_done_time;
//已经运行时间
intdone_time;
//完成时间
intturn_around_time;
//周转时间
floatwei_turn_around_time;
//带权周转时间
structprocess*next;
};
inttime=-1;
inttime_slice=4
;
//时间片初始值为1
Isempty(structprocess*head)
{
if(head->
next==NULL)
returntrue;
elsereturnfalse;
}
voidpushline(structprocess*head,structprocess*rn)
if(rn==NULL)
return;
structprocess*x;
x=head;
while(x->
next!
=NULL)
x=x->
next;
}
x->
next=rn;
voidpopline(structprocess*head,structprocess**x)
if(!
Isempty(head))
*x=head->
head->
next=(*x)->
(*x)->
next=NULL;
}
voidisnewcome(structprocess*head,structprocess*readyline)
next->
arri_time==time&
&
head->
cout<
<
time<
"
time"
anewprocessarrive"
endl;
popline(head,&
x);
pushline(readyline,x);
voidmain()
structprocess*head;
structprocess*newnode;
structprocess*tail;
structprocess*readyline;
//队列
readyline=(structprocess*)malloc(sizeof(process));
readyline->
inti;
structprocess*rightnow;
structprocess*p;
/*structprocess*n;
*/
head=(structprocess*)malloc(sizeof(process));
head)
内存分配错误"
head->
tail=head;
while
(1)
newnode=(structprocess*)malloc(sizeof(process));
请输入进程名"
cin>
>
newnode->
name;
if(newnode->
name=='
#'
)
break;
请输入进程到达时间"
arri_time;
请输入进程服务时间"
serv_time;
newnode->
done_time=0;
turn_around_time=0;
wei_turn_around_time=0.0;
have_done_time=0;
//tail->
next=newnode;
//tail=newnode;
pushline(head,newnode);
p=head->
while(p!
p->
name<
进程"
p=p->
ss:
while(time<
200)
time++;
//cout<
当前TIME"
isnewcome(head,readyline);
if(time!
=0)
pushline(readyline,rightnow);
i=time_slice;
i="
i<
while(i!
{
//cout<
DANGQIANGTIME"
if(i==time_slice)
{
i--;
if(!
Isempty(readyline))
{
popline(readyline,&
rightnow);
rightnow->
have_done_time++;
done_time=time;
cout<
run"
rightnow->
if(rightnow->
have_done_time==rightnow->
serv_time)
{rightnow->
turn_around_time=rightnow->
done_time-rightnow->
arri_time+1;
rightnow->
wei_turn_around_time=(float)rightnow->
turn_around_time/rightnow->
cout<
********************"
endl<
havedone!
turn_around_time:
turn_around_time<
wei_turn_around_time:
wei_turn_around_time<
rightnow=NULL;
gotoss;
}
//else
//pushline(readyline,rightnow);
}
else//break;
gotoss;
}
else
time++;
isnewcome(head,readyline);
//popline(readyline,&
rightnow->
cout<
if(rightnow->
arri_time+1rightnow->
rightnow=NULL;
//else
//pushline(readyline,rightnow);
}}
/*readyline=head->
head=readyline->
p=readyline;
readyline=read