主题:[原创]计算机操作系统实验-进程调度(续2)
void print_fun(PCB *H[3],char diao
[10*MAXP],int countd)
{
/*输出就绪队列函数*/
int i;
PCB *q;
cout<<diao[countd-1]<<" ";
for(i=0;i<3;i++)
{
cout<<i<<":";
q=H[i];
while(q!=NULL)
{
cout<<q->name<<" ";
q=q->next;
}
}
}
//----------------------------------------
--------------------------
int main(int argc, char* argv[])
{
int
n,time=0,isstop,countd=0,i,signNULL,sign,t
[3]={1,2,4};
/*
n进程个数 isstop进程是否结束 countd总调度
次数
signNULL就绪队列是否为空 sign是否有运行的
t[3]时间片大小
*/
PCB p[MAXP],*H[3];
char diao[10*MAXP]; /*调度序列
*/
for(i=0;i<3;i++)
H[i]=NULL;
n=input_func(p); /*输入*/
time=p[0].arrive;
isstop=2;
getnewqueue_fun(p,n,H,time,isstop,i); /*获
得就绪队列*/
while(H[0]!=NULL||H[1]!=NULL||H[2]!=NULL)
{ sign=0;
for(i=0;i<3&&sign==0;i++)
{
if(H[i]!=NULL)
{sign=1;
H[i]->condition='R';
if(H[i]->serve>t[i]) /*在时
间片内运行不完*/
{H[i]->serve-=t[i];
time+=t[i];
H[i]->arrive=time;
diao[countd]=H[i]->name;
countd++;
isstop=0;
H[i]->condition='W';
getnewqueue_fun
(p,n,H,time,isstop,i);
}
else{time+=H[i]->serve; /*
在时间片内运行完*/
H[i]->serve=0;
H[i]->condition='F';
diao[countd]=H[i]->name;
countd++;
isstop=1;
getnewqueue_fun
(p,n,H,time,isstop,i);
print_fun
(H,diao,countd);
cout<<endl;
}
}
}
signNULL=1; /*看就绪队列是否为空
*/
for(i=0;i<n;i++)
if(H[i]!=NULL)
signNULL=0;
if(signNULL)
{for(sign=1,i=0;i<n&&sign;i++)
if(p[i].condition=='W')
{
time=p[i].arrive;
sign=0;
}
isstop=2;
getnewqueue_fun(p,n,H,time,isstop,i);
sign=0;
}
}//end while
for(i=0;i<countd;i++) /*输出总调度序列
*/
{cout<<diao[i];
if(i%20==0&&i!=0)
cout<<endl;
}
cout<<endl;
return 0;
}
[10*MAXP],int countd)
{
/*输出就绪队列函数*/
int i;
PCB *q;
cout<<diao[countd-1]<<" ";
for(i=0;i<3;i++)
{
cout<<i<<":";
q=H[i];
while(q!=NULL)
{
cout<<q->name<<" ";
q=q->next;
}
}
}
//----------------------------------------
--------------------------
int main(int argc, char* argv[])
{
int
n,time=0,isstop,countd=0,i,signNULL,sign,t
[3]={1,2,4};
/*
n进程个数 isstop进程是否结束 countd总调度
次数
signNULL就绪队列是否为空 sign是否有运行的
t[3]时间片大小
*/
PCB p[MAXP],*H[3];
char diao[10*MAXP]; /*调度序列
*/
for(i=0;i<3;i++)
H[i]=NULL;
n=input_func(p); /*输入*/
time=p[0].arrive;
isstop=2;
getnewqueue_fun(p,n,H,time,isstop,i); /*获
得就绪队列*/
while(H[0]!=NULL||H[1]!=NULL||H[2]!=NULL)
{ sign=0;
for(i=0;i<3&&sign==0;i++)
{
if(H[i]!=NULL)
{sign=1;
H[i]->condition='R';
if(H[i]->serve>t[i]) /*在时
间片内运行不完*/
{H[i]->serve-=t[i];
time+=t[i];
H[i]->arrive=time;
diao[countd]=H[i]->name;
countd++;
isstop=0;
H[i]->condition='W';
getnewqueue_fun
(p,n,H,time,isstop,i);
}
else{time+=H[i]->serve; /*
在时间片内运行完*/
H[i]->serve=0;
H[i]->condition='F';
diao[countd]=H[i]->name;
countd++;
isstop=1;
getnewqueue_fun
(p,n,H,time,isstop,i);
print_fun
(H,diao,countd);
cout<<endl;
}
}
}
signNULL=1; /*看就绪队列是否为空
*/
for(i=0;i<n;i++)
if(H[i]!=NULL)
signNULL=0;
if(signNULL)
{for(sign=1,i=0;i<n&&sign;i++)
if(p[i].condition=='W')
{
time=p[i].arrive;
sign=0;
}
isstop=2;
getnewqueue_fun(p,n,H,time,isstop,i);
sign=0;
}
}//end while
for(i=0;i<countd;i++) /*输出总调度序列
*/
{cout<<diao[i];
if(i%20==0&&i!=0)
cout<<endl;
}
cout<<endl;
return 0;
}