




免费预览已结束,剩余18页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实验五实验五 进程调度模拟实验进程调度模拟实验 进程调度算法 proc c include include include typedef struct pcb 定义 PCB 结构 char name 20 进程标识符 int cputime 进程占用 CPU 时间 int prio 进程优先数 int needtime 进程到完成还需要的 CPU 时间 struct pcb next 链指针 PCB PCB RUN READY RTAIL FINSH FTAIL void PRINTLINK int t 输出 3 个队列 PCB p printf CPU 运行次数 d n t printf n printf 进程名 t 运行状态 t 运行次数 t 还需要运行次数 n if RUN NULL printf s t 运行 t d t d n RUN name RUN cputime RUN needtime else printf 运行状态为空 n p READY if p NULL while p NULL printf s t 就绪 t d t d n p name p cputime p needtime p p next else printf 就绪队列为空 n p FINSH if p NULL while p NULL printf 进程名字为 s n p name printf s t 完成 t d t d n p name p cputime p needtime p p next else printf 完成队列为空 n getchar PCB CPCBLINK 建立就绪队列 printf 建立就绪队列 n n int i n nt pr PCB p q head n 0 while 1 printf 请输入进程的个数 有效范围 1 100 scanf d printf n if n 1 while 1 printf 需要的运行时间 scanf d if nt 0 break else printf 输入无效 重新输入 n getchar head needtime nt printf 优先数 scanf d head prio pr head cputime 0 进程已获得的运行时间 head next NULL q head for i 1 iname printf 需要的运行时间 scanf d p needtime nt printf 优先数 scanf d p prio pr p cputime 0 进程已获得的运行时间 p next NULL q next p q p RTAIL q return head void JXDLPX 就绪队列按优先级从大到小排序 PCB p q t char s 10 int L 0 ct pr nt p READY t struct pcb malloc sizeof struct pcb while p next NULL L 0 q p next t p while q NULL if t prioprio t q L 1 表示有比它优先级大的进程 q q next if L 1 strcpy s t name ct t cputime pr t prio nt t needtime q p next while strcmp q name s 0 q q next strcpy q name p name q cputime p cputime q prio p prio q needtime p needtime strcpy p name s p cputime ct p prio pr p needtime nt p p next void YXS 调用优先数调度算法调用优先数调度算法 PCB p int t 0 nt ct pr printf 您选择的是 优先级调度算法 n READY CPCBLINK 建立就绪队列 p struct pcb malloc sizeof struct pcb while READY NULL JXDLPX 就绪队列按优先级从大到小排序 p READY READY READY next p next NULL pr p prio pr pr 3 p prio pr 运行 1 次进程优先级缩小 3 nt p needtime nt nt 1 p needtime nt ct p cputime ct ct 1 p cputime ct RUN p PRINTLINK t 输出 3 个队列 if RUN needtimenext p FTAIL FTAIL next RUN NULL else 若运行没结束进入就绪队列 if READY NULL 当就绪队列为空 READY p RTAIL p else RTAIL next p RTAIL p RUN NULL t void SJP 调用时间片循环轮转算法 PCB p printf 您选择的是 时间片循环轮转调度算法 n int t 0 nt ct READY CPCBLINK 建立就绪队列 p struct pcb malloc sizeof struct pcb while READY NULL p READY READY READY next p next NULL nt p needtime nt nt 2 if ntneedtime nt ct p cputime ct ct 2 p cputime ct RUN p PRINTLINK t 输出 3 个队列 if RUN needtimenext p FTAIL FTAIL next RUN NULL else 若运行没结束进入就绪队列 if READY NULL 当就绪队列为空 READY p RTAIL p else RTAIL next p RTAIL p RUN NULL t 主程序 int main int N RUN struct pcb malloc sizeof struct pcb while 1 RUN NULL READY NULL RTAIL NULL FINSH NULL FTAIL NULL printf n printf 进程调度算法演示程序 n printf n printf 1 优先级调度算法 n printf 2 时间片循环轮转算法 n printf 3 退出 n printf n printf 请选择 scanf d if N 1 YXS 调用优先数调度算法 else if N 2 SJP 调用时间片循环轮转算法 else if N 3 break else printf 您输入的信息有误 请重新输入 n n getchar printf 演示程序结束 n n getchar return 0 1 流程图 2 实验结果 3 编写简化的多级反馈队列调度算法 要求只有三级队列 进程在第一级队列中时 采用时间片轮转执行 如果该进程没有执行 完毕 其进入第二级队列 第二级队列中也采用时间片轮转算法 但时间片长度是第一级 队列时间片长度的二倍 以此类推 长进程在第三级队列中最终执行完毕 如果进程在第 一级队列中就已经执行完毕 则在第一级队列中结束进程 如在第二级队列中执行完毕 则在第二级队列中结束进程 include include include typedef struct pcb 定义 PCB 结构 char name 20 进程标识符 int cputime 进程占用 CPU 时间 int prio 进程优先数 int needtime 进程到完成还需要的 CPU 时间 struct pcb next 链指针 int ltime 时间片长度 PCB PCB RUN READY RTAIL FINSH FTAIL void PRINTLINK int t 输出 3 个队列 PCB p printf CPU 运行次数 d n t printf n printf 进程名 t 运行状态 t 运行次数 t 还需要运行次数 n if RUN NULL printf s t 运行 t d t d n RUN name RUN cputime RUN needtime else printf 运行状态为空 n p READY if p NULL while p NULL printf s t 就绪 t d t d n p name p cputime p needtime p p next else printf 就绪队列为空 n p FINSH if p NULL while p NULL printf 进程名字为 s n p name printf s t 完成 t d t d n p name p cputime p needtime p p next else printf 完成队列为空 n getchar PCB CPCBLINK 建立就绪队列 printf 建立就绪队列 n n int i n nt pr PCB p q head n 0 while 1 printf 请输入进程的个数 有效范围 1 100 scanf d printf n if n 1 while 1 printf 需要的运行时间 scanf d if nt 0 break else printf 输入无效 重新输入 n getchar head needtime nt printf 优先数 scanf d head prio pr head cputime 0 进程已获得的运行时间 head next NULL q head for i 1 iname printf 需要的运行时间 scanf d p needtime nt printf 优先数 scanf d p prio pr p cputime 0 进程已获得的运行时间 p next NULL q next p q p RTAIL q return head void SJP 调用时间片循环轮转算法 PCB p printf 您选择的是 时间片循环轮转调度算法 n int t 0 nt ct READY CPCBLINK 建立就绪队列 p struct pcb malloc sizeof struct pcb while READY NULL p READY READY READY next p next NULL nt p needtime nt nt ltime if ntneedtime nt ct p cputime ct ct ltime p cputime ct p ltime 2 RUN p PRINTLINK t 输出 3 个队列 if RUN needtimenext p FTAIL FTAIL next RUN NULL else 若运行没结束进入就绪队列 if READY NULL 当就绪队列为空 READY p RTAIL p else RTAIL next p RTAIL p RUN NULL t 主程序 void main int N RUN struct pcb malloc sizeof struct pcb while 1 RUN NUL
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 游戏公司企业文化
- Photoshop平面设计基础 课件 任务5.3 制作旅行社T型广告牌海报
- 住宅租赁安全责任与装修安全协议
- 地质灾害监测测量员聘请与预警协议
- 车辆安全保险理赔处理协议
- 通信材料回购方案
- 住宅小区停车场租赁合同规范范本及停车管理
- 餐饮企业股权转让及品牌推广权合同
- 太仓历史面试题及答案
- 手绘校园面试题及答案
- 【电商直播对消费者购买行为影响:以抖音直播为例开题报告1800字】
- 抑郁病诊断证明书
- 气体分析仪检定规程
- 2024-2029年吞咽困难饮食增稠剂行业市场现状供需分析及市场深度研究发展前景及规划投资研究报告
- (高清版)WST 348-2024 尿液标本的采集与处理
- FZT 73012-2017 文胸行业标准
- 肺系病的中医护理
- 四型机场方案
- 体育运动与劳动教学计划结合
- 肿瘤登记基本技术肿瘤命名与编码课件
- 全国各省市县-一览表
评论
0/150
提交评论