#include "stdio.h"
#include <stdlib.h>
#include <conio.h>
#define getpch(type) (type*)malloc(sizeof(type))
#define NULL 0
struct pcb { /* 定义进程控制块PCB */
char name[10];
char state[100];
int waittime; int xtime;
int ntime;
int rtime;
struct pcb* link;
}*ready=NULL,*p,*t=NULL;
typedef struct pcb PCB;
sort() /* 建立对进程进行优先级排列函数*/
{
p->link=ready; ready=p;
} sort1() {p->link=t; ready=p;
}
input() /* 建立进程控制块函数*/
{
int i,num;
clrscr(); /*清屏*/
printf("\n 请输入进程号:");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\n 进程号No.%d:\n",i);
p=getpch(PCB);
printf("\n 输入进程名:");
scanf("%s",p->name);
printf("\n阻塞进程的时间片 :");
scanf("%d",&p->waittime);
printf("\n 进程要运行的时间:");
scanf("%d",&p->ntime); printf("\n阻塞时间:"); scanf("%d",&p->xtime);
printf("\n");
p->rtime=0;
p->link=NULL;
sort(); /* 调用sort函数*/
}
}
int space()
{
int l=0; PCB* pr=ready;
while(pr!=NULL)
{
l++;
pr=pr->link;
}
return(l);
}
disp(PCB * pr) /*建立进程显示函数,用于显示当前进程*/
{
printf("\n qname \t state \t waittime \t ndtime \t runtime \t xtime\n");
printf("|%s\t",pr->name);
printf("|%c\t",pr->state);
printf("|%d\t",pr->waittime);
printf("|%d\t",pr->xtime);
printf("|%d\t",pr->ntime);
printf("|%d\t",pr->rtime);
printf("\n");
} check() /* 建立进程查看函数 */
{
PCB* pr; PCB* pp;
printf("\n当前正在运行的进程是:%s",p->name); /*显示当前运行进程*/
disp(p);
pr=ready;
printf("\n当前就绪队列状态为:\n"); /*显示就绪队列状态*/
while(pr!=NULL)
{
disp(pr);
pr=pr->link;
} pp=t;
printf("\n阻塞队列状态为:\n");
while(pp!=NULL)
{ disp(pp);
pp=pp->link; }
}
destroy() /*建立进程撤消函数(进程运行结束,撤消进程)*/
{
printf("\n 进程 [%s] 已完成.\n",p->name);
free(p);
}
running() /* 建立进程就绪函数(进程运行时间到,置就绪状态*/
{PCB *ptr; while(p->rtime!=p->ntime) {p->rtime++; printf("\n当前所运行的进程状态为:"); disp(p); ptr=t; while(ptr!=NULL) {ptr->xtime--; if(ptr->xtime==0) {p=ptr; sort(); } ptr->link=ptr; } if(p->rtime==p->waittime)
{ printf("\n该进程被阻塞:");
sort1();
break;} }
if(p->rtime==p->ntime) destroy();
}
main() /*主函数*/
{
int len,h=0;
input();
len=space(); printf("%d",len);
while((ready!=NULL))
{
h++;
printf("\n The execute number:%d \n",h);
p=ready;
ready=p->link;
check();
running();
printf("\n 按任一键继续......");
}
printf("\n\n 进程已经完成.\n");
} 帮我看一下有什么问题?