




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统实验报告一 实验一 进程状态转换及其PCB的变化一、实验目的:自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容 、组织的变化,理解进程与其PCB间的一一对应关系。二、实验内容及要求:(1)、 设计并实现一个模拟进程状态转换及其相应PCB内容、组织结构变化的程序。(2)、 独立编写、调试程序。进程的数目、进程的状态模型(三状态、五状态、七状态或其它)以及PCB的组织形式可自行选择。(3)、 合理设计与进程PCB相对应的数据结构。PCB的内容要涵盖进程的基本信息、控制信息、资源需求及现场信息。(4)、 设计出可视性较好的界面,应能反映出进程状态的变化引起的对应PCB内容、组织结构的变化。(5)、 代码书写要规范,要适当地加入注释。(6)、 鼓励在实验中加入新的观点或想法,并加以实现。(7)、 认真进行预习,完成预习报告。 (8)、 实验完成后,要认真总结,完成实验报告。五状态模型: 3、 主要数据结构:struct Run_type /运行态进程char name;int state;int needtime;int priority;struct Ready_type /就绪态进程char name;int needtime;int priority;struct Blocked_type /阻塞态进程char name;int needtime;int priority;4、 程序源代码:#include#include#includeint i=0; int j=0;struct Run_typechar name;int state;int needtime;int priority;struct Ready_typechar name;int needtime;int priority;struct Blocked_typechar name;int needtime;int priority;struct Run_type Cpu;struct Ready_type Ready10;struct Blocked_type Blocked10;void Creat()/创建一个新的进程int k=0;label1:printf( input new process name(input a letter): n);scanf(%s,&(R);getchar();for(k=0;ki;k+)if(R=R|R=R+32|R=R-32)printf(the process is already exist!);goto label1;printf(input needtime (input a int number):n);label3:scanf(%d,&(Readyi.needtime);getchar();if(Readyi.needtime100)printf(please input the true needtime(1-100)n);goto label3;printf( input the priority(1-10): n);label2:scanf(%d,&(Readyi.priority);getchar();if(Readyi.priority10)printf(please 1-10!n);goto label2;i+;void Dispath()/P135 int t;char v;int k;int j;if(Cpu.state=0)if(Readyi-1.needtime=0)printf(* there is no process ready!n);exit(0);elsefor(k=0;ki-1;k+)for(j=0;jReadyj+1.priority)t=Readyj.priority;Readyj.priority=Readyj+1.priority;Readyj+1.priority=t;t=Readyj.needtime;Readyj.needtime=Readyj+1.needtime;Readyj+1.needtime=t;v=R;R=Readyj+1.name;Readyj+1.name=v;-i;C=R;Cpu.needtime=Readyi.needtime;Cpu.priority=Readyi.priority;Cpu.state=1;printf(*%5c is send to cpu! n,C);Cpu.needtime-;if(Cpu.needtime=0)printf(*%5c is finished n,C);Cpu.state=0;else R=C;Readyi.needtime=Cpu.needtime;Readyi.priority=Cpu.priority;for(k=0;ki;k+)for(j=0;jReadyj+1.priority)t=Readyj.priority;Readyj.priority=Readyj+1.priority;Readyj+1.priority=t;t=Readyj.needtime;Readyj.needtime=Readyj+1.needtime;Readyj+1.needtime=t;v=R;R=Readyj+1.name;Readyj+1.name=v;C=R;Cpu.needtime=Readyi.needtime;Cpu.priority=Readyi.priority;Cpu.state=1;printf(*%5c is send to cpu! n,C);Cpu.needtime-;if(Cpu.needtime=0)printf(*%5c is finished n,C);Cpu.state=0;void Timeout()if(Cpu.state=0)printf(* there is no process in cpu(please select Dispath!n);exit(0);elseR=C;Readyi.needtime=Cpu.needtime;Readyi.priority=Cpu.priority;printf(%c is timeout n,C);C=0;Cpu.needtime=0;Cpu.priority=0;Cpu.state=0;i+;void Eventwait()if(Cpu.state!=0)B=C;Blockedj.needtime=Cpu.needtime;Blockedj.priority=Cpu.priority;printf(* %c is Blocked !n,C);j+;C=B;Cpu.needtime=Blockedj.needtime;Cpu.priority=Blockedj.priority;Cpu.state=0;elseprintf(* There is no process in cpu!);void Eventoccurs(char a)int k=0;int m=0;int n=0;int p=0;if(Blocked0.needtime=0)printf(* there is no process blocked!n);exit(0);elsefor(k;kj;k+)if(B=a)R=B;Readyi.needtime=Blockedk.needtime;Readyi.priority=Blockedk.priority;p=1;m=j-k;for(n;nm;n+)B=Blockedk+1.name;Blockedk.needtime=Blockedk+1.needtime;Blockedk.priority=Blockedk+1.priority;k+;j-;i+;if(p=1)printf(* %c is ready!n,a);elseprintf(* %c is not found! n,a);void main()Cpu.state=0;int Cputime=0;int x=6;while(x!=0)printf(n1:input new process 2:Dispathn);printf(3:Timeout 4:Eventwaitn);printf(5:Eventoccurs(select whose eventoccur ) 0:exitn);label4:scanf(%d,&x);getchar();printf(n=n);if(x=0|x=1|x=2|x=3|x=4|x=5)switch(x)case 1:Creat();break;case 2:Dispath();break;case 3:Timeout();break;case 4:Eventwait();break;case 5:char a;scanf(%c,&a);getchar(); Eventoccurs(a);break;default:printf(please select from 0 to 5n);printf(- Cputime:%3d -n,Cputime);printf(| ProceNsname NeedTime Priority |n);if(Cpu.state!=0)/显示Cpu中的程序printf(| Cpu:%16c,C);printf(%20d,Cpu.needtime);printf(%18d |n,Cpu.priority);elseprintf(| * Cpu is free |n);int y=0;if(i=0)/显示Ready队列中的数据printf(| *There is no process ready. |n);elsefor(y;yi;y+)/显示Ready中的程序printf(| Ready%d:,y);printf(%15c,R);printf(%20d,Readyy.needtime);printf(%18d |n,Readyy.priority);int z=0;if(j=0) /显示Blocked队列中的程序printf(| *There is no process blocked. |n);elsefor(z;zj;z+)printf(| Blocked%d:,z);printf(%13c,B);printf(%20d,Blockedz.needtime);printf(%18d |n,Blockedz.priority); Cputime+; if(Cpu.state!=0) Cpu.needtime=Cpu.needtime-1;printf(-n);elseprintf(please input 0-5n);goto label4;5、 运行结果:1. 创建a,b两个进程2
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离婚时共同财产投资收益分配协议书范本
- 矿业权转让居间协议书(含矿山安全生产培训)
- 副校长培训课件
- 辽宁省安全培训资格课件
- 导弹创意绘画课件
- 辅警专业知识培训课件
- 工商银行2025七台河市秋招群面模拟题及高分话术
- 工商银行2025肇庆市秋招笔试创新题型专练及答案
- 2025年3D打印技术的纳米3D打印技术
- 2025年3D打印技术的材料创新方向
- 模特老师培训课件模板
- IATF16949内审员培训资料
- 危重病人约束护理
- 艾梅乙反歧视培训课件
- 劳模创新工作室申报材料
- 蜂蛰伤的治疗指南讲课件
- GB/T 45785-2025压缩空气站能源绩效评价
- 非物质文化遗产保护与乡村振兴的协同发展路径
- 窑炉施工安全管理制度
- QGDW10936-2018物料主数据分类与编码规范
- 大学生劳动教育论文2000字论文
评论
0/150
提交评论