struct pb
{int n;
int k;
int cha;};
typedef struct pb PCB;
PCB a[10];
void creat()
{static int pi=1;
int k,l=0,m;
printf("plase input n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=1;
if (l==1)
{printf("error!\n");
creat(); }
else
{a[pi].n=m;
printf("\n");
printf("plase input k0:");
scanf("%d",&a[pi].k);
printf("\n");
a[pi++].cha=4;}}
void destory()
{int i,num,k=0;
printf(" plase input destory number:");
scanf("%d",&num);
for(i=1;i<=10;i++)
if(a[i].n==num) k=i;
if(k!=0)
{a[k].n=0;a[k].k=0;a[k].cha=0;}
else
printf("No have this destory number!\n");}
void wakeup()
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
a[l].cha=1; /*喚醒->靜止就緒*/}
void active()
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
a[l].cha=3; /*激活->活動就緒*/}
void dse()
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
a[l].cha=4; /*阻塞->活動阻塞*/}
void swpend()
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
a[l].cha=2; /* 掛起->靜止阻塞 */}
void look()
{int i;
printf("\t\tpcb n0 k0 cha\n");
for (i=1;i<=10;i++)
printf("\t\t%d\t%d\t%d\t%d\n",i,a[i].n,a[i].k,a[i].cha);
printf("\t1--靜止就緒 2--靜止阻塞 3--活動就緒 4--活動阻塞 5--運行\n");}
void zt() /* 改變狀態*/
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
printf("請輸入當前狀態:");
scanf("%d",&a[l].cha);
look();}
void yxs() /*改變優先數*/
{int i,k,m,l;
printf("請輸入n0:");
scanf("%d",&m);
for(k=1;k<=10;k++)
if (a[k].n==m)
l=k;
printf("請輸入優先數:");
scanf("%d",&a[l].k);
look();}
main()
{int d;
clrscr();
do
{
printf("\t\t*************** CHOICE *****************\n");
printf("\t\t* 1--------------進程創建 *\n");
printf("\t\t* 2--------------進程撤消 *\n");
printf("\t\t* 3--------------阻塞 *\n");
printf("\t\t* 4--------------喚醒 *\n");
printf("\t\t* 5--------------掛起 *\n");
printf("\t\t* 6--------------激活 *\n");
printf("\t\t* 7--------------查看狀態 *\n");
printf("\t\t* 8--------------改變狀態 *\n");
printf("\t\t* 9--------------改變優先數 *\n");
printf("\t\t* 0--------------退出 *\n");
printf("\t\t****************************************\n");
printf("\t\t請選擇(0-9):");
scanf("%d",&d);
printf("\n");
switch(d)
{
case 1: creat();break;
case 2: destory();break;
case 3: dse();break;
case 4: wakeup();break;
case 5: swpend();break;
case 6: active();break;
case 7:look();break;
case 8:zt();break;
case 9:yxs();break;
case 0: exit(0);
}
}
while(d!=0);
}