日期:2014-05-20 浏览次数:20748 次
#include<iostream>
#include<string>
#include<time.h>
using namespace std;
int n;
class PCB
{
public:
int pri;//进程优先数
int runtime;//进程运行CPU时间
int pieceOftime;//轮转时间片
string procname;//进程名
string state;//进程状态
int needOftime;//还需要时间
int Counter;
PCB * next;
};
PCB * run = NULL;
PCB * ready = NULL;
PCB * finish = NULL;
PCB * tial = ready;
void Dtime(int t)
{
time_t current_time;
time_t start_time;
time(&start_time);
do
{
time(& current_time);
}
while((current_time-start_time)<t);
}
void Prinft(int a)
{
if(a==1)
{
cout<<"进程名称"<<"\t"<<"优先数"<<"\t"<<"还需要时间"<<"\t"<<"已运行时间"<<"\t"<<"状态:"<<endl;
}
else
cout<<"进程名称"<<"\t"<<"已运行时间"<<"\t"<<"还需要时间"<<"\t"<<"计数器"<<"\t"<<"时间片"<<"\t"<<"状态"<<endl;
}
void Prinft(int b,PCB * p)
{
if(b==1)
{
cout<<p->procname<<"\t\t"<<p->pri<<"\t"<<p->needOftime<<"\t\t"<<p->runtime<<"\t\t"<<p->state<<endl;
}
else
cout<<p->procname<<"\t\t"<<p->runtime<<"\t\t"<<p->needOftime<<"\t\t"<<p->Counter<<"\t"<<p->pieceOftime<<"\t"<<p->state<<endl;
}
void display(int c)
{
PCB *p;
if(run!=NULL) /*如果运行指针不空*/
Prinft(c,run); /*输出当前正在运行的PCB*/ //Dtime(2);
p=ready; /*输出就绪队列PCB*/
while(p!=NULL)
{
Prinft(c,p);
p=p->next;
} //Dtime(2);
p=finish; /*输出完成队列的PCB*/
while(p!=NULL)
{
Prinft(c,p);
p=p->next;
}
}
void insert(PCB *p)//插入就绪队列按Pri大小
{
PCB *S1,*S2;
if(ready==NULL)
{
p->next = NULL;
ready = p;
}
else
{
S1 = ready;
S2 = S1;
while(S1!=NULL)
{
if(S1->pri >= p->pri)
{
S2 = S1;
S1 = S1->next;
}