




免费预览已结束,剩余7页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
操作系统实验报告 班 级物联网1302班学 号姓 名 实验2 进程状态转换及其PCB的变化1目的:自行编制模拟程序,通过形象化的状态显示,深入理解进程的概念、进程之间的状态转换及其所带来的PCB内容 、组织的变化,理解进程与其PCB间的一一对应关系。2. 内容及要求:1) 设计并实现一个模拟进程状态转换及其相应PCB内容、组织结构变化的程序。2) 独立编写、调试程序。进程的数目、进程的状态模型(三状态、五状态、七状态或其它)以及PCB的组织形式可自行选择。3) 合理设计与进程PCB相对应的数据结构。PCB的内容要涵盖进程的基本信息、控制信息、资源需求及现场信息。4) 设计出可视性较好的界面,应能反映出进程状态的变化引起的对应PCB内容、组织结构的变化。5) 代码书写要规范,要适当地加入注释。6) 认真进行预习,完成预习报告。7) 实验完成后,要认真总结,完成实验报告。3使用的数据结构及说明:在本实验中,主要用到的数据结构是PCB的结构,其中PCB的数据结构如下:enum StatusRunning,Ready,Blocked,Exit;struct PCBint id; /进程号int priority;/优先级enum Status status;/进程状态char name;/进程名称;struct Runningstruct PCB pcb;struct Running *pcbnext;struct Running *header_running;struct Readystruct PCB pcb;struct Ready *pcbnext;struct Ready *header_ready, *tail_ready;struct Blockedstruct PCB pcb;struct Blocked *pcbnext;struct Blocked *header_blocked, *tail_blocked;struct Exitint id;char name;struct Exit *pcbnext;struct Exit *header_exit,*tail_exit;4. 流程图5 程序源代码,注释及说明文字:Main.c#include#include#includeprocess.h#includeint main()int i = 1;int choice = -1;header_running = (struct Running *) malloc(sizeof(struct Running); /创建运行状态队列头if (NULL = header_running)perror(error);exit(1);header_running-pcbnext = NULL;header_ready = (struct Ready *) malloc(sizeof(struct Ready);/创建就绪队状态列头if (NULL = header_ready)perror(error);exit(1);header_ready-pcbnext = NULL;header_blocked = (struct Blocked *) malloc(sizeof(struct Blocked);/创建阻塞队状态列头if (NULL = header_blocked)perror(error);exit(1);header_blocked-pcbnext = NULL;header_exit = (struct Exit *) malloc(sizeof(struct Exit);/创建僵死状态队列头if (NULL = header_exit)perror(error);exit(1);header_exit-pcbnext = NULL;tail_ready = header_ready;tail_blocked = header_blocked;tail_exit = header_exit;printf(请输入要创建的进程个数n);scanf(%d, &num);while (num = 0)printf(进程个数应大于0,请重新输入n);scanf(n%d, &num);for (i;i );ready-pcb.id = i;ready-pcb.priority = i;ready-pcb.status = Ready;ready-pcbnext = NULL;tail_ready-pcbnext = ready;tail_ready = ready;printf(*n);printf(* 0-创建进程 1-就绪-运行 *n);printf(* 2-运行-就绪 3-运行到阻塞 *n);printf(* 4-阻塞-就绪 5-运行-终止 *n);printf(*n);while (1)printf(n请输入你要进行的转换:t);scanf(%d, &choice);switch (choice)case 0:status0();print();break;case 1:status1();print();break;case 2:status2();print();break;case 3:status3();print();break;case 4:status4();print();break;case 5:status5();print();break;default:printf(没有这个选项,请重新输入!n);break;printf(n);return 0;/Process.c#include#include#includeprocess.h/*创建进程*/void status0(void)struct Ready *ready = (struct Ready *) malloc(sizeof(struct Ready);if (NULL = ready)perror(error);exit(1);printf(请输入要创建的进程的名称:t, &);scanf(n%c, &);ready-pcb.id = num+1;ready-pcb.priority = +num;ready-pcb.status = Ready;ready-pcbnext = NULL;tail_ready-pcbnext = ready;tail_ready = ready;/*就绪-运行*/void status1(void)if (NULL = header_running-pcbnext) /没有程序正在运行if (NULL != header_ready-pcbnext) /就绪组中有就绪的进程header_running-pcbnext = header_ready-pcbnext;header_ready-pcbnext = header_ready-pcbnext-pcbnext;header_running-pcbnext-pcb.status = Running; /进程状态变为运行状态else printf(暂时没有就绪程序,请稍等!n);else /有正在运行的程序if (header_running-pcb.priority pcb.priority) /正在运行的程序的优先级小于要调度的进程的优先级,进行调度tail_ready-pcbnext = header_running-pcbnext;header_running-pcbnext = header_ready-pcbnext;header_ready-pcbnext = header_ready-pcbnext-pcbnext;header_running-pcbnext-pcb.status = Running;else printf(正在运行的进程的优先级大于被调度的进程的优先级,调度失败n);/*运行-就绪*/void status2(void)if (NULL != header_ready-pcbnext) /就绪队列不为空tail_ready-pcbnext = header_running-pcbnext; /运行的程序放在就绪队列尾部tail_ready = tail_ready-pcbnext;tail_ready-pcb.status = Ready; /状态变为就绪tail_ready-pcbnext = NULL;header_running-pcbnext = header_ready-pcbnext; /就绪队列的第一个进程放到运行队列header_running-pcbnext-pcb.status = Running;header_ready-pcbnext = header_ready-pcbnext-pcbnext;/*运行-阻塞*/void status3(void)tail_blocked-pcbnext = header_running-pcbnext; /将运行的进程放到阻塞状态的队列尾部tail_blocked = tail_blocked-pcbnext;tail_blocked-pcb.status = Blocked;tail_blocked-pcbnext = NULL;header_running-pcbnext = NULL;if (NULL != header_ready-pcbnext) /就绪组中有就绪的进程header_running-pcbnext = header_ready-pcbnext; /就绪队列的第一个进程放到运行队列header_ready-pcbnext = header_ready-pcbnext-pcbnext;header_running-pcbnext-pcb.status = Running; /进程状态变为运行状态/*阻塞-就绪*/void status4(void)char name;struct Blocked *blocked = header_blocked;printf(请输入要解除阻塞状态的进程的名称t);scanf(n%c, &name);while (NULL !=blocked-pcbnext)if ( = name) /阻塞队列中有要解除阻塞状态的进程,将进程放入就绪队列if (NULL = header_running-pcbnext) /运行队列为空if (NULL = header_ready-pcbnext) /就绪队列为空header_running-pcbnext = blocked-pcbnext;header_running-pcbnext-pcb.status = Running;blocked-pcbnext = blocked-pcbnext-pcbnext;break;else tail_ready-pcbnext = blocked-pcbnext; /放到就绪队列尾部tail_ready = tail_ready-pcbnext;tail_ready-pcb.status = Ready;tail_ready-pcbnext = NULL;blocked-pcbnext = blocked-pcbnext-pcbnext;break;if (NULL != blocked-pcbnext)printf(没有该进程!n);/*运行-终止*/void status5(void)struct Exit *EXit = (struct Exit *)malloc(sizeof(struct Exit);if (NULL = exit)perror(error);exit(1);/*将终止的进程放入终止状态*/EXit-id = header_running-pcbnext-pcb.id;EXit-name = header_;EXit-pcbnext = NULL;tail_exit-pcbnext = EXit;tail_exit = tail_exit-pcbnext;/*回收终止了的进程的内存空间*/struct Running *running = header_running-pcbnext;header_running-pcbnext = NULL;free(running);void print(void)struct Ready *ready = header_ready-pcbnext;struct Blocked *blocked = header_blocked-pcbnext;struct Exit *exit = header_exit-pcbnext;printf(正在运行的进程是:t);if(NULL != header_running-pcbnext)printf(%c, header_);printf(n);printf(处于就绪状态的进程的有:t);while (NULL != ready)printf(%c, , ready-pcb.na
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025福建省榕江进出口有限公司招聘1人笔试历年参考题库附带答案详解
- 2025福建漳州城投建材集团有限公司劳务派遣招聘5人笔试历年参考题库附带答案详解
- 2025赤峰龙韵城市建设有限公司所属子公司员工招聘21人模拟试卷及答案详解参考
- 2025湖北襄阳市保康国有资本投资集团有限公司招聘12人笔试历年参考题库附带答案详解
- 2025浙江温州市鹿通文化旅游有限公司招聘工作人员10人笔试历年参考题库附带答案详解
- 2025广东“百万英才汇南粤”佛山市高明区选聘公办初中校长9人考前自测高频考点模拟试题及答案详解(典优)
- 2025广西壮族自治区山口红树林生态国家级自然保护区管理中心招聘考前自测高频考点模拟试题附答案详解(黄金题型)
- 2025恒丰银行成都分行春季校园招聘6人考前自测高频考点模拟试题及答案详解(有一套)
- 2025年宁夏电力集体资产投资集团有限公司高校毕业生招聘(第三批)考前自测高频考点模拟试题及答案详解(夺冠系列)
- 2025北京邮电大学与通信工程学院招聘1人(人才派遣)考前自测高频考点模拟试题及答案详解(易错题)
- 飞行器故障诊断与容错
- 叉车工作手册
- 中小学教师职称评审讲课答辩英语学科全英答辩题目汇编(附汉语翻译)
- 应聘人员登记表
- 预防高处坠落安全监理细则
- 贝朗DIALOG+透析机水路设计概览课件
- 光电功能材料课程-13-18课件
- 施工现场污水排放方案
- 黔西市中医医院金阳院区环评报告
- 我的家乡-枣阳
- 青春期生理卫生知识讲座男生篇
评论
0/150
提交评论