实验二带优先级的时间片轮换的进程调度算法的实现.ppt

上传人:tia****nde 文档编号:8838195 上传时间:2020-04-01 格式:PPT 页数:19 大小:866.31KB
返回 下载 相关 举报
实验二带优先级的时间片轮换的进程调度算法的实现.ppt_第1页
第1页 / 共19页
实验二带优先级的时间片轮换的进程调度算法的实现.ppt_第2页
第2页 / 共19页
实验二带优先级的时间片轮换的进程调度算法的实现.ppt_第3页
第3页 / 共19页
点击查看更多>>
资源描述
带优先级的时间片轮换的进程调度算法的实现 一 实验目的 1 掌握进程状态转换过程 2 掌握时间片轮转的进程调度算法 3 掌握带优先级的进程调度算法 二 实验内容 1 自定义PCB的数据结构 2 使用带优先级的时间片轮转法调度进程 每运行一个时间片 优先级减半 3 命令集A create随机创建进程 进程的优先级与所需要的时间片随机决定 B round执行1次时间片轮转操作 其方法为运行高优先级队列的第1个 再降低其优先级 插入到相应的队列中 C ps查看当前进程状态D sleep命令将进程挂起E awake命令唤醒1个被挂起的进程F kill命令杀死进程G quit命令退出 4 选用面向对象的编程方法 三 实验原理或算法本实验结合了进程状态转换 优先级调度 时间片轮转调度三方面的内容 根据进程状态转换图 设置SLEEP命令 将1个进程挂起 AWAKE命令唤醒1个被挂起的进程 从阻塞状态到就绪状态 1 优先级优先级体现了进程的重要程度或紧迫程度 在大多数现代操作系统中 都采用了优先级调度策略 优先级从小到大 如0 127 优先级最高 127最低 在本实验中按数值大小决定优先级 数值大的优先级高 2 基于时间片调度将所有的就绪进程按照先来先服务的原则 排成一个队列 每次调度时 将cpu分配给队首进程 并令其执行一个时间片 当时间片用完时 由一个计时器发出时钟中断请求 调度程序把此进程终止 把该进程放到队尾 在该实验中 时间片以100ms为单位 实际的要小得多 在调度过程中 需要通过时间函数检测进程的执行时间 当该进程执行时间 时间片大小时 进行调度 3 高优先级调度优先级高的进程优先得到cpu 等该进程执行完毕后 另外的进程才能执行 4 基于时间片的高优先级调度在调度算法中 只有处于就绪状态的进程才能被调度 调度算法结合了优先级调度和时间片轮转调度算法 约定 从最高优先级队列取第1个就绪状态的进程进行调度 时间片到后降低其优先级 降低一半 然后插入到低优先级队列的尾部 每次调度后 显示进程的状态 四 数据结构及符号说明structpcb PCB intident 标识符intstate 状态0 就绪 1 运行 2 堵塞intpior 优先级 MAXPIOR为最高优先级 intlife 生命期 structpcb next 指针 voidinit intcreate voidps voidawake intx voidkill intx voidprocess 对输入命令的处理voidroutine 执行一次调度运行 将最高优先级队列的进程运行1个时间片 并降低其优先级 六 实验源程序 include include include definegetpch type type malloc sizeof type structpcb 定义进程控制块PCB charname 10 charstate intsuper intneedtime intruntime structpcb link ready NULL p typedefstructpcbPCB intident 标识符intstate 状态0 就绪 1 运行 2 堵塞intpior 优先级 MAXPIOR为最高优先级 intlife 生命期 structpcb next 指针 intcreate inti 0 pior 0 structpcb p q s while idlist i 0 voidsleep intx inti 0 test 0 structpcb p NULL q NULL while test 0 p array pior 建立同优先级队列 链表 if p NULL array pior s else while p NULL q p p p next q next s printf successcreateprocessid d currentprocessstatedispbelow n s ident ps printf enddisplay n return1 voidps inti 0 structpcb p for i 0 iident p state p pior p life p p next if i MAXPIOR printf Invaildprocessnumber elseif p state 2 printf theprocess dhasblocked cannotsleepagain p ident elsep state 2 ps voidawake intx inti 0 test 0 structpcb p NULL q NULL while test 0 while p NULL if p ident x test 1 killtest 1 break else q p p p next if test 0 i 找到X所在指针 if i MAXPIOR printf Invaildprocessnumber elseif p state 0 printf theprocess disreadystate cannotawakeagain p ident elsep state 0 ps voidkill intx inti 0 test 0 structpcb p NULL q NULL while test 0 if i MAXPIOR else q next p next idlist x 0 life life p life free p voidprocess 对输入命令的处理 inti 0 ii 0 for i 0 i 7 i if stricmp str command i 0 break switch i case0 printf thankyouforusingtheprogram n exit 0 break case1 ps break case2 create break case3 printf Whichprocessyouwanttokill n scanf d voidroutine 执行一次调度运行 将最高优先级队列的进程运行1个时间片 并降低其优先级 inti MAXPIOR 1 pior 0 t structpcb pp qq pr r do while i 0 进程处于就绪状态if r life QUANTUM 0 r life r life QUANTUM 时间减少QUANTUMlife life QUANTUM else life life r life r life 0 if r life 0 进程运行完成 KILL它 printf theprocess dissuccessfulrun andreleaseit n r ident kill r ident else if pr r 将r结点从原队列中删除array i 1 r next elsepr next r next t r pior 将r进程加入到相应低优先级队列中的最后pp array t qq NULL while pp NULL qq pp pp pp next if qq NULL 插入到队尾array t r elseqq next r r next NULL printf after n ps printf n1quantumsuccessfulrun n voidmain init printf WelcometotheProcessSchedulingsystem ThisprogramsimulatetheRound RobinwithpirorSchedulingalogrithm n printf c scanf s str process while strcmp str quit 0 printf nc scanf s str process 谢谢观赏
展开阅读全文
相关资源
相关搜索

当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!