




已阅读5页,还剩8页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
。操作系统实验-进程状态转换及其PCB的变化1. 目的: 自行编制模拟程序,通过形象化的状态显示,使学生理解进程的概念、进程之间的状态转换及其所带来的PCB内容 、组织的变化,理解进程与其PCB间的一一对应关系。2. 内容及要求:1) 设计并实现一个模拟进程状态转换及其相应PCB内容、组织结构变化的程序。2) 独立编写、调试程序。进程的数目、进程的状态模型(三状态、五状态、七状态或其它)以及PCB的组织形式可自行选择。3) 合理设计与进程PCB相对应的数据结构。PCB的内容要涵盖进程的基本信息、控制信息、资源需求及现场信息。4) 设计出可视性较好的界面,应能反映出进程状态的变化引起的对应PCB内容、组织结构的变化。5) 代码书写要规范,要适当地加入注释。6) 鼓励在实验中加入新的观点或想法,并加以实现。7) 认真进行预习,完成预习报告。8) 实验完成后,要认真总结,完成实验报告。3. 程序流程图4.代码部分(1) 数据结构部分进程结构体struct PCBchar P_name10;int P_id; int P_state;int needtime;int lefttime;int P_level;进程结构体有:进程号,进程状态,进程剩下的时间,进程需要的时间,进程的优先级队列结构体struct QueuePCB qNode5;int queueLength;定义的队列最多有5个进程。(2)程序解释这里做的是对操作系统课程里面将的“3 状态”的模型的模拟,给它提供的初始状态是有5个进程,而进程所需要的时间和进程的状态都是随机产生的,并把就绪队列里面的进程按照进程的优先级(P_level)进行排序,设置初始状态时没有在运行的程序。(3)程序的代码/#include #include #include #include struct PCBchar P_name10;int P_id;int P_state;int needtime;int leavetime;int P_level;struct QueuePCB qNode5;int queueLength;int insertQueue(Queue *q,PCB *p)int i=0;if (q-queueLength=0)q-qNodei=*p;q-queueLength+;return 1;elsewhile(p-P_levelqNodei.P_level)i+;for (int j=q-queueLength;j=i;j-)q-qNodej=q-qNodej-1;q-qNodei=*p;q-queueLength=q-queueLength+1;return 1;void setQueue(PCB pcb5,Queue *ready,Queue *blocked,Queue *finish)ready-queueLength=0;blocked-queueLength=0;finish-queueLength=0;for (int i=0;iqNodeblocked-queueLength=pcbi;blocked-queueLength+;void show(Queue ready,Queue blocked,Queue fininsh,PCB run)printf(n完成队列n);printf(进程名-优先级-所需时间-剩余时间n);for (int i=0;ifininsh.queueLength;i+)printf(%s%d%d%d%dn,fininsh.qNodei.P_name,fininsh.qNodei.P_id,fininsh.qNodei.P_level,fininsh.qNodei.needtime,fininsh.qNodei.leavetime);printf(n);if (run.needtime!=0)printf(当前正在运行的进程:n);printf(进程名-优先级-所需时间-剩余时间n);printf(%s%d%d%d%dn,run.P_name,run.P_id,run.P_level,run.needtime,run.leavetime);printf(n);printf(就绪队列n);printf(进程名-优先级-所需时间-剩余时间n);for ( i=0;iready.queueLength;i+)printf(%s%d%d%d%dn,ready.qNodei.P_name,ready.qNodei.P_id,ready.qNodei.P_level,ready.qNodei.needtime,ready.qNodei.leavetime);printf(n);printf(阻塞队列n);printf(进程名-优先级-所需时间-剩余时间n);for (i=0;iblocked.queueLength;i+)printf(%s%d%d%d%dn,blocked.qNodei.P_name,blocked.qNodei.P_id,blocked.qNodei.P_level,blocked.qNodei.needtime,blocked.qNodei.leavetime);void P_levelRun(Queue ready,Queue blocked,Queue finish,PCB run)int i_blocked=0;int i_finish=0;while(finish.queueLength!=5)printf(*n);int i_ready=0;if (run.needtime!=0)run.leavetime-;if (run.needtime!=0&run.leavetime=0)finish.qNodei_finish=run;finish.queueLength+;i_finish+;run.needtime=0;if (ready.queueLength!=0)run=ready.qNodei_ready;for (;i_readyready.queueLength;i_ready+)ready.qNodei_ready=ready.qNodei_ready+1;ready.queueLength=ready.queueLength-1;elseint temp=run.P_id;if (run.P_level=ready.qNode0.P_level)insertQueue(&ready,&run);run.needtime=0;printf(时间片用尽,%s%d进入就绪队列,优先级更高的%s%d开始运行!n,run.P_name,run.P_id,ready.qNode0.P_name,ready.qNode0.P_id);elseprintf(时间片用尽,但是没有更高优先级的进程,%s%d继续运行n,run.P_name,run.P_id);else if (run.needtime=0)if (ready.queueLength!=0)run=ready.qNodei_ready;for (;i_readyready.queueLength;i_ready+)ready.qNodei_ready=ready.qNodei_ready+1;ready.queueLength=ready.queueLength-1;if (blocked.queueLength!=0)srand(int) time(0);int temp=rand()%2;if (temp=1)printf(n%s%d所需资源产生,进程从阻塞队列转到就绪队列n,&blocked.qNodei_blocked.P_name,blocked.qNodei_blocked.P_id);insertQueue(&ready,&blocked.qNodei_blocked);blocked.queueLength=blocked.queueLength-1;if (blocked.queueLength!=0)for (int i=0;iblocked.queueLength+1;i+)blocked.qNodei=blocked.qNodei+1;else if(temp=0)printf(n%s%d所需资源没有产生,等待。n,&blocked.qNodei_blocked.P_name,blocked.qNodei_blocked.P_id);show(ready,blocked,finish,run);void main()Queue ready,blocked,finish;PCB pcb5;PCB run;run.needtime=0;printf(设置了5个进程!n说明:进程的状态,所需时间和优先级等是随机产生的。nnn);srand(int) time(0);for (int i=0;i5;i+)pcbi.P_name0=P;pcbi.P_name1=r;pcbi.P_name2=o;pcbi.P_name3=c;pcbi.P_name4=e;pcbi.P_name5=s;pcbi.P_name6=s;pcbi.P_name7=0;pcbi.P_id=i;pcbi.P_state=rand()%2;pcbi.P_level=rand()%10+1;pcbi.needtime=rand()%2+1;pcbi.leavetim
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度智能网络IT运维服务外包与优化升级合同
- 2025年农村宅基地房屋买卖及预售交付时间详细约定范本
- 2025年度城市绿地生态修复项目场地平整施工服务合同
- 2025年文物遗址修复与文化遗产保护综合施工合同
- 2025年智能办公空间租赁与买卖一体化服务合同
- 2025年度城市轨道交通线路设计招标与施工管理合同
- 2025年叉车行业定制化租赁及维修保养合同范本
- 2025年企业内部安全保卫与保安劳务输出管理协议
- 2025年智能大厦安保服务与人员聘用综合合同范本
- 2025年度遗体告别仪式专用场地租赁与生态绿化维护服务合同
- 艾梅乙检测结果解读培训课件
- ESD静电管理评审计划+管理评审报告全套资料
- 04735数据库系统原理-串讲
- 绿色工厂培训课件
- 制造业的网络安全培训
- 接触网工程图识图 六跨电分相绝缘锚段关节安装图的识图
- 工业厂房监理规划范本
- 中建硅墨烯保温板外墙保温施工方案
- 急性心肌梗死的护理PPT
- 花卉学 二年生花卉
- 管道工程隐蔽验收记录表
评论
0/150
提交评论