欢迎来到天天文库
浏览记录
ID:14841610
大小:49.50 KB
页数:7页
时间:2018-07-30
《操作系统实验(模拟进程管理)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、操作系统实验————(1)模拟进程管理专业:信息管理与信息系统班级:信管082姓名:温静实验一进程管理1.目的和要求通过实验理解进程的概念,进程的组成(PCB结构),进程的并发执行和操作系统进行进程管理的相关原语(主要是进程的创建、执行、撤消)。2.实验内容用C语言编程模拟进程管理,至少要有:创建新的进程;查看运行进程;换出某个进程;杀死运行进程以及进程之间通信等功能。3.主体程序#include#include#includestructPCB_type{intpid;intprior
2、ity;intcputime;intstate;intshumu=0,pid_l;structPCB_typeneicun[20];structPCB_typehc[10];intmax=0;intnumber=0;voidcreate();voidrun();voidhuanchu();voidkill();/*创建新进程*/voidcreate(){if(shumu>=20){printf("内存已满,请先结束或换出进程");}else{shumu++;printf("请输入新进程的程序名");scanf("%d",&ne
3、icun[shumu-1].pid);printf("请输入新进程的优先级");scanf("%d",&neicun[shumu-1].priority);printf("请输入新进程的运行时间");scanf("%d",&neicun[shumu-1].cputime);printf("创建进程时令其状态为就绪");neicun[shumu-1].state=2;}printf("创建进程成功!");}/*查看当前运行进程*/voidrun(){intmax=0;for(inti=0;i4、{if((neicun[i].state==1)&&(neicun[i].priority>=neicun[max].priority))max=i;}neicun[max].state=3;printf("当前运行进程程序名:%d",neicun[max].pid);printf("该进程的优先级:%d",neicun[max].priority);printf("该进程的运行时间:%d",neicun[max].cputime);printf("该进程的状态:%d",neicun[max].state);}/*5、换出*/voidhuanchu(){intk;printf("请输入要换出程序的程序名:");scanf("%d",&k);for(intj=0;j6、icun[j].state=0;neicun[j].priority=0;neicun[j].cputime=0;pid_1++;}elseprintf("进程%d无法换出的pid:%d",j.neicun[j].pid);if(number!=0)for(inti=0;i7、"该进程的状态:%d",hc[i].state);}}PCB_typetemp=neicun[0];for(k=0;k<=shumu;k++){if(neicun[k].priority>temp.priority)tmpe=neicun[k];}neicun[k].state=1;}/*杀死进程*/voidkill(){neicun[max].pid=0;neicun[max].priority=0;neicun[max].cputime=0;neicun[max].state=0;if(max==(shumu-1))shumu--8、;else{for(intj=max+1;j
4、{if((neicun[i].state==1)&&(neicun[i].priority>=neicun[max].priority))max=i;}neicun[max].state=3;printf("当前运行进程程序名:%d",neicun[max].pid);printf("该进程的优先级:%d",neicun[max].priority);printf("该进程的运行时间:%d",neicun[max].cputime);printf("该进程的状态:%d",neicun[max].state);}/*
5、换出*/voidhuanchu(){intk;printf("请输入要换出程序的程序名:");scanf("%d",&k);for(intj=0;j6、icun[j].state=0;neicun[j].priority=0;neicun[j].cputime=0;pid_1++;}elseprintf("进程%d无法换出的pid:%d",j.neicun[j].pid);if(number!=0)for(inti=0;i7、"该进程的状态:%d",hc[i].state);}}PCB_typetemp=neicun[0];for(k=0;k<=shumu;k++){if(neicun[k].priority>temp.priority)tmpe=neicun[k];}neicun[k].state=1;}/*杀死进程*/voidkill(){neicun[max].pid=0;neicun[max].priority=0;neicun[max].cputime=0;neicun[max].state=0;if(max==(shumu-1))shumu--8、;else{for(intj=max+1;j
6、icun[j].state=0;neicun[j].priority=0;neicun[j].cputime=0;pid_1++;}elseprintf("进程%d无法换出的pid:%d",j.neicun[j].pid);if(number!=0)for(inti=0;i7、"该进程的状态:%d",hc[i].state);}}PCB_typetemp=neicun[0];for(k=0;k<=shumu;k++){if(neicun[k].priority>temp.priority)tmpe=neicun[k];}neicun[k].state=1;}/*杀死进程*/voidkill(){neicun[max].pid=0;neicun[max].priority=0;neicun[max].cputime=0;neicun[max].state=0;if(max==(shumu-1))shumu--8、;else{for(intj=max+1;j
7、"该进程的状态:%d",hc[i].state);}}PCB_typetemp=neicun[0];for(k=0;k<=shumu;k++){if(neicun[k].priority>temp.priority)tmpe=neicun[k];}neicun[k].state=1;}/*杀死进程*/voidkill(){neicun[max].pid=0;neicun[max].priority=0;neicun[max].cputime=0;neicun[max].state=0;if(max==(shumu-1))shumu--
8、;else{for(intj=max+1;j
此文档下载收益归作者所有