📄 process.h
字号:
#include "struct.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <malloc.h>
#include "iomanip"
#define null 0
#define OVERFLOW -2
#define ERROR 0
#include "iostream"
using namespace std;
class PCBQueue
{
public: PCB *front;
public: PCB *rear;
//int mutex;
PCBQueue()
{front=rear=(PCB*)malloc(sizeof(PCB));
if (!front)
exit(OVERFLOW);
else
{
strcpy(front->name,"nullqueue");
front->flag=-1;
front->size=0;
front->server=0;
front->arrive=-1;
front->start=0;
front->next=null;
}
}
bool inqueue(PCBNode &p)
{p->next=null;
rear->next=p;
rear=p;
return true;
}
bool outqueue(PCBNode &p)
{
if(front==rear) return false;
p=front->next;
front->next=p->next;
if (rear==p) rear=front;
return true;
}
bool isnull()
{
if (front==rear)
return true;
else
return false;
}
int number()
{ int i=0;
PCBNode p=front;
while(p!=rear)
{
p=p->next;
i++;
}
return i;
}
void traverse()
{
if(isnull())
cout<<"就绪队列为空。"<<endl;
else
{
cout<<"就绪进程数为:"<<number()<<endl;
PCBNode p;
p=front->next;
for(int i=0;i<number();i++)
{
cout<<"进程名字:"<<p->name<<"\t"<<"进程标识符:"<<p->flag<<endl;
p=p->next;
}
}
}
//
bool tellprocessmessage(int flag)
{
PCBNode p;
p=findprocess(flag);
if(p)
{
cout<<"进程 名字:"<<p->name<<endl;
cout<<"进程标识符:"<<p->flag<<endl;
cout<<"进程 大小:"<<p->size<<endl;
cout<<"进程创建时间:"<<p->arrive<<endl;
cout<<"进程服务时间:"<<p->server<<endl;
}
return true;
//
}
PCBNode findprocess(int flag)
{
PCBNode p;
p=front;
while(p)
{
if(p->flag!=flag)
p=p->next;
else
break;
}
if(!p)
cout<<"没有此进程。"<<endl;
return p;
}
~PCBQueue()
{
if(front)
free(front);
if(rear)
free(rear);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -