- UID
- 1029342
- 性别
- 男
|
#define M 200
#include "conio.h"
#include "stdio.h"
typedef struct pcb /*进程控制块的定义*/
{
char Processname[M]; /*进程名*/
int runtime; /*运行时间*/
int arrivetime; /*到达时间*/
char state; /*进程状态*/
struct pcb*next; /*链接指针*/
}PCB;
PCB head_input;
PCB head_run;
PCB*pcb_input;
static char R='r',C='c';
unsigned long current; /*记录系统当前时间的变量*/
int Processready(); /*建立就绪队列函数*/
int Dataready(); /*判断进程是否就绪函数*/
void inputprocess(); /*建立进程函数*/
int runprocess(); /*运行进程函数*/
int Processready()
{
while(1)
{
if(Dataready()==0)
return 1;
else
runprocess();
}
}
int Dataready()
{
if(head_input.next==NULL)
{
if(head_run.next==NULL)
return 0;
else
return 1;
}
PCB *p1,*p2,*p3;
p1=head_run.next;
p2=&head_run;
while(p1!=NULL)
{
p2=p1;
p1=p2->next;
}
p1=p2;
p3=head_input.next;
p2=&head_input;
while(p3!=NULL)
{
if(((unsigned long)p3->arrivetime<=current)&&(p3->state==R))
{
printf("╭───────────────────╮\n");
printf("|时间片是:%d(时间:%d),进程%s开始 |\n",current,(current+500)/1000,p3->Processname);
printf("╰───────────────────╯\n");
p2->next=p3->next;
p3->next=p1->next;
p1->next=p3;
p3=p2;
}
p2=p3;
p3=p3->next;
}
return 1;
} |
|