用C语言编写进程的创建与取消。
- 提问者网友:斑駁影
- 2021-03-08 14:36
- 五星知识达人网友:第幾種人
- 2021-03-08 15:50
- 1楼网友:鱼芗
- 2021-03-08 16:53
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); }