用c语言编写模拟进程控制程序

如题:用c语言编写模拟进程控制程序操作系统... 如题:用c语言编写模拟进程控制程序操作系统 展开
 我来答
匿名用户
2013-11-10
展开全部
#define null 0
#define M " Menu\n\n1.Creat a process\n2.Destroy a process\n3.Blockaprocess\n4.Wakeup a process\n5.Suspend a process\n6.Active a process\n7.Observe the processes\n\nPlease select the item you want to realize:"struct PCB
{char name;<br> int ko;<br> int cha;<br>}struct PCB pcb[10];
int i=0;void creat()
{char a;<br> int b;<br> printf("Please input the name of the process:");<br> scanf("%c",&a);<br> printf("\nPlease input the ko of the process:");<br> scanf("%d",&b);<br> i++;<br> pcb[i].name=a;<br> pcb[i].ko=b;<br> pcb[i].cha=1;<br> printf(M);<br>}void destroy()
{char a;<br> int j;<br> printf("Select a process you want to destroy:");<br> scanf("%c",&a);<br> printf("\n");<br> for(j=1;j<=10;j++)<br> {if(pcb[j].name==a)<br> {pcb[j].name=0;<br> pcb[j].ko=0;<br> pcb[j].cha=0;<br> printf("Process %c has been destroied.");<br> }
else printf("There isn't process %c existed!");
}
printf("\n");
printf(M);
}void block()
{char a;<br> int j;<br> printf("Please tell me which process you want to block:");<br> scanf("%c",&a);<br> printf("\n");<br> for(j=1;j<=10;j++)<br> {if(pcb[j].name==a)<br> {if(pcb[j].cha==1)<br> {pcb[j].cha=4;<br> pcb[j].ko++;<br> printf("Operation block has been finished!");<br> }
else if(pcb[j].cha==2)
{pcb[j].cha=3;<br> pcb[j].ko++;<br> printf("Operation block has been finished!");<br> }
else printf("There is no process can be blocked!");
}
}
printf("\n");
printf(M);
}void wakeup()
{char a;<br> int j;<br> printf("Please tell me which process you want to wakeup:");<br> scanf("%c",&a);<br> printf("\n");<br> for(j=1;j<=10;j++)<br> {if(pcb[j].name==a)<br> {if(pcb[j].cha==3)<br> {pcb[j].cha=2;<br> pcb[j].ko--;<br> printf("You have wakeup process %c.",a);<br> }
else if(pcb[j].cha==4)
{pcb[j].cha=1;<br> pcb[j].ko--;<br> printf("You have wakeup process %c.",a);<br> }
else printf("There is no process can be wakedup!");
}
}
printf("\n");
printf(M);
}void suspend()
{char a;<br> int j;<br> printf("Which process do you want to suspend?Select:");<br> scanf("%c",&a);<br> printf("\n");<br> for(j=1;j<=10;j++)<br> {if(pcb[j].name==a)<br> {if(pcb[j].cha==2)<br> {pcb[j].cha=1;<br> pcb[j].ko++;<br> printf("You have suspend process %c.",a);<br> }
else if(pcb[j].cha==3)
{pcb[j].cha=4;<br> pcb[j].ko++;<br> printf("You have suspend process %c.",a);<br> }
else if(pcb[j].cha==5)
{pcb[j].cha=1;<br> pcb[j].ko++;<br> printf("You have suspend process %c.",a);<br> }
else printf("You could suspend none!");
}
}
printf("\n");
printf(M);
}void active()
{char a;<br> int j;<br> printf("Please tell me which process you want to active:");<br> scanf("%c",&a);<br> printf("\n");<br> for(j=1;j<=10;j++)<br> {if(pcb[j].name==a)<br> {if(pcb[j].cha==1)<br> {pcb[j].cha=2;<br> pcb[j].ko--;<br> printf("You have active process %c.",a);<br> }
else if(pcb[j].cha==4)
{pcb[j].cha=3;<br> pcb[j].ko--;<br> printf("You have active process %c.",a);<br> }
else printf("There is no process can be actived!");
}
}
printf("\n");
printf(M);
}void run()
{struct PCB *p;<br> char t;<br> int j,m,k;<br> printf("The processes will run in the order of ko(lower earlier,higher later):\n");<br> for(j=1,p=pcb;p!=null;j++,p++)<br> {if(p[j].ko>p[j+1].ko)<br> {t=p[j].name;<br> p[j].name=p[j+1].name;<br> p[j+1].name=t;<br> m=p[j].cha;<br> p[j].cha=p[j+1].cha;<br> p[j+1].cha=m;<br> k=p[j].ko;<br> p[j].ko=p[j+1].ko;<br> p[j+1].ko=k;<br> }
}
for(p=pcb,j=1;p!=null;p++)
{printf("Process %c:",p[j].name);<br> printf("\tko:%d\tcha:%d",p[j].ko,p[j].cha);<br> printf("\n");<br> }
printf("\n");
printf(M);
} observe()
{int j;<br> for(j=1;j!=null;j++)<br> {printf("Process %c:",pcb[j].name);<br> printf("\tko:%d\tcha:%d",pcb[j].ko,pcb[j].cha);<br> printf("\n");<br> }
}exit()
{exit(1);<br>}main()
{int a,k;<br> for(k=1;k<=10;k++)<br> {pcb[i].name=0;<br> pcb[i].ko=0;<br> pcb[i].cha=0;<br> }
printf(" Menu\n\n");
printf("1.Creat a process\n");
printf("2.Destroy a process\n");
printf("3.Block a process\n");
printf("4.Wakeup a process\n");
printf("5.Suspend a process\n");
printf("6.Active a process\n");
printf("7.Observe the processes\n");
printf("8.Exit\n");
printf("\n\n");
printf("\n\nPlease select the item you want to realize:");
scanf("%d",&a);
printf("\n\n");
if(a!=null)
switch(a)
{case 1:creat();break;<br> case 2:destroy();break;<br> case 3:block();break;<br> case 4:wakeup();break;<br> case 5:suspend();break;<br> case 6:active();break;<br> case 7:observe();break;<br> case 8:exit();break;<br> }
getch();
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式