先来先服务和短作业优先调度算法文档格式.docx
《先来先服务和短作业优先调度算法文档格式.docx》由会员分享,可在线阅读,更多相关《先来先服务和短作业优先调度算法文档格式.docx(24页珍藏版)》请在冰点文库上搜索。
【实验过程】
#include<
iostream>
usingnamespacestd;
#defineMaxNum100
intArrivalTime[MaxNum];
doubleServiceTime[MaxNum];
doubleFinishTime[MaxNum];
doubleWholeTime[MaxNum];
doubleAVEWholeTime[MaxNum];
doubleAVEWeightWholeTime[MaxNum];
doubleWeightWholeTime[MaxNum];
doubleAverageWT_FCFS,AverageWT_SJF;
doubleAverageWWT_FCFS,AverageWWT_SJF;
doubleAllTime,WeightAllTime;
doublea[MaxNum];
intb[MaxNum];
intc[MaxNum];
intd[MaxNum];
voidFCFS();
voidSJF();
voidFCFS()
{
intProcessNum;
cout<
<
"
----------先来先服务算法----------"
endl;
请输入进程个数:
;
cin>
>
ProcessNum;
输入进程到达时间:
for(inti=0;
i<
i++)
{
cin>
ArrivalTime[i];
//cout<
}
请输入进程服务时间:
ServiceTime[i];
FinishTime[i]=ServiceTime[i];
FinishTime[i+1]=FinishTime[i]+FinishTime[i+1];
ProcessNum-1;
cout<
时刻"
FinishTime[i]<
:
第"
i+2<
个进程开始运行。
PCFS完成时间:
"
PCFS周转时间:
WholeTime[i]=FinishTime[i]-ArrivalTime[i];
WholeTime[i]<
PCFS平均周转时间:
AVEWholeTime[i]=WholeTime[i];
AVEWholeTime[i]<
AVEWholeTime[i+1]=AVEWholeTime[i]+AVEWholeTime[i+1];
AVEWholeTime[i+1]<
AllTime=AVEWholeTime[i+1];
AllTime<
AverageWT_FCFS=AllTime/ProcessNum;
平均周转时间"
AverageWT_FCFS<
PCFS带权周转时间:
WeightWholeTime[i]=WholeTime[i]/ServiceTime[i];
WeightWholeTime[i]<
PCFS平均带权周转时间:
AVEWeightWholeTime[i]=WeightWholeTime[i];
AVEWeightWholeTime[i]<
AVEWeightWholeTime[i+1]=AVEWeightWholeTime[i]+AVEWeightWholeTime[i+1];
WeightAllTime=AVEWeightWholeTime[i+1];
WeightAllTime<
AverageWWT_FCFS=WeightAllTime/ProcessNum;
平均带权周转时间"
AverageWWT_FCFS<
}
voidSJF()
----------短作业优先算法----------"
a[i]=ServiceTime[i];
for(inti=1;
i++)//实现从第一位开始排序
doubleexchange;
for(intj=i+1;
j<
j++)
{
if(a[i]>
a[j])
{
exchange=a[i];
a[i]=a[j];
a[j]=exchange;
}
}
FinishTime[0]=ServiceTime[0];
i++)//获取数组下标
//b[0]=0;
for(intj=1;
if(a[i]==ServiceTime[j])
b[i]=j;
//cout<
break;
FinishTime[b[i-1]]<
ArrivalTime[b[i]]<
b[i]<
/**
***通过下边的转换,使得完成时间小于到达时间时
***下一个进程和下下一个进程顺序交换
**/
if(FinishTime[b[i-1]]<
ArrivalTime[b[i]])
//cout<
b[i+1]<
inttemp;
temp=b[i];
b[i]=b[i+1];
b[i+1]=temp;
a[i]=ServiceTime[b[i]];
a[i]=a[i-1]+a[i];
a[i]<
FinishTime[b[i]]=a[i];
SJF完成时间:
SJF周转时间:
SJF平均周转时间:
//cout<
AllTime;
AverageWT_SJF=AllTime/ProcessNum;
AverageWT_SJF<
SJF带权周转时间:
SJF平均带权周转时间:
AverageWWT_SJF=WeightAllTime/ProcessNum;
AverageWWT_SJF<
voidmain()
charflag='
Y'
charn;
----------调度算法FCFS&
&
SJF-----------"
while(flag=='
||flag=='
y'
)
{
1、先来先服务FCFS算法."
2、短作业优先SJF算法."
请您选择算法的序号:
n;
switch(n)
case'
1'
FCFS();
break;
case'
2'
SJF();
break;
default:
cout<
您输出有误!
是否继续调度算法FCFS&
SJF,按'
or'
钮继续,按照'
N'
n'
键退出"
flag;
【实验结果】
先来先服务算法
短作业优先算法
printf("
);
scanf("
%d"
&
ProcessNum);
\n"
scanf("
&
ArrivalTime[i]);
for(i=0;
printf("
for(i=1;
cou