?? jincheng.txt
字號:
#include "stdio.h"
#include <stdlib.h>
#include <conio.h>
#define getpch(type) (type*)malloc(sizeof(type))
#define NULL 0
struct pcb {
char name[10];
char state;
int super;
int ntime;
int rtime;
struct pcb* link;
}*ready=NULL,*p;
typedef struct pcb PCB;
void sort()
{
PCB *first, *second;
int insert=0;
if((ready==NULL)||((p->super)>(ready->super)))
{
p->link=ready;
ready=p;
}
else
{
first=ready;
second=first->link;
while(second!=NULL)
}
if((p->super)>(second->super))
{
p->link=second;
first->link=p;
second=NULL;
insert=1;
}
else
{
first=first->link;
second=second->link;
}
if(insert==0) first->link=p;
}
void input()
{
int i,num;
printf("\n Please put the Process ID?\n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("\n Process ID is:\n",i);
p=getpch(PCB);
printf("\n Process Name:");
scanf("%s",p->name);
printf("\n Process Super :");
scanf("%d",&p->super);
printf("\n Process Runtime:");
scanf("%d",&p->ntime);
printf("\n");
p->rtime=0;p->state='w';
p->link=NULL;
sort();
}
}
void disp(PCB * pr)
{
printf("\n qname \t state \t super \t ndtime \t runtime \n");
printf("|%s\t",pr->name);
printf("|%c\t",pr->state);
printf("|%d\t",pr->super);
printf("|%d\t",pr->ntime);
printf("|%d\t",pr->rtime);
printf("\n");
}
void check()
{
PCB* pr;
printf("\n ****Now Running Process is:%s",p->name);
disp(p);
pr=ready;
printf("\n ****Now these Processes are ready:\n");
while(pr!=NULL)
{
disp(pr);
pr=pr->link;
}
}
void destroy()
{
printf("\n Process [%d] is finished.\n",p->name);
free(p);
}
void running()
{
(p->rtime)++;
if(p->rtime==p->ntime)
destroy();
else
{
(p->super)--;
p->state='w';
sort();
}
}
void main()
{
int len,h=0;
char ch;
input();
len=5;
while((len!=0)&&(ready!=NULL))
{
ch=getchar();
h++;
printf("\n The execute number:%d \n",h);
p=ready;
ready=p->link;
p->link=NULL;
p->state='R';
check();
running();
printf("\n Press any key continue ......");
ch=getchar();
}
printf("\n Process has finished. \n");
ch=getchar();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -