




已阅读5页,还剩16页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
精品文档 1欢迎下载 静态优先权优先算法的进程调度程序静态优先权优先算法的进程调度程序 学 院 专 业 学 生 姓 名 学 号 指导教师姓名 21014 年 3 月 19 日 精品文档 2欢迎下载 目 录 1 系统需求分析 1 1 1 问题描述 1 1 2 功能要求 1 2 总体设计 1 2 1 总体设计图 1 2 2 各模块功能 2 2 3 相关数据结构设计 3 3 详细设计 3 3 1 采用 C 语言定义的相关数据类型 3 3 2 调度算法的主要实现 4 4 运行结果 4 4 1 系统调试 4 4 2 功能实现界面 5 5 使用说明 7 6 心得体会 8 7 附录 8 7 1 源代码 8 7 2 参考文献 17 精品文档 1欢迎下载 1 系统需求分析 1 1 问题描述 1 设计并实现一个采用静态优先权算法的进程调度演示程序 并且求出每 个进程的周转时间以及带权周转时间 2 静态优先权是在创建进程时确定的 且在进程的整个运行期间保持不变 一般地 优先权是利用某一范围内的一个整数来表示的 例如 0 7 或 0 255 中的某一整数 又把该整数称为优先数 只是具体用法各异 有的系统用 0 表示 最高优先权 当数值愈大时 其优先权愈低 而有的系统恰恰相反 确定进程优先权的依据有如下三个方面 a 进程类型 系统进程 用户进程 b 进程对资源的需求 需求量的大小 c 用户要求 用户进程紧迫程度 3 本程序采用优先级数字大的优先权大 1 2 功能要求 1 每一个进程有一个 PCB 其内容可以根据具体情况设定 2 进程数 进入内存时间 要求服务时间 优先级等均可以在界面上设定 3 可读取样例数据 要求存放在外部文件中 进行进程数 进入内存时间 进 程优先级的初始化 4 可以在运行中显示各进程的状态 就绪 执行 由于不要求设置互斥资源 与进程间的同步关系 故只有两种状态 5 具有一定的数据容错性 精品文档 2欢迎下载 2 总体设计 2 1 总体设计图 系统总体设计如图 2 1 所示 1 进程的创建及模拟 输 入 进 程 数 输 入 优 先 级 输 入 进 入 内 存 时 间 输 入 服 务 时 间 输 出 运 行 结 果 静态优先权优先算法 2 读取文件数据及模 拟 输 出 运 行 结 果 图 2 1 系统总体设计 2 2 各模块功能 1 void buildProcess 手动创建进程 2 struct PCB callMemory 将符合条件的进程调入内存 3 void ListAllPCB struct PCB h 打印所有进程到屏幕上 0 结 束 精品文档 3欢迎下载 4 void Menu 菜单以及执行 5 void newPCB 创建进程 在 1 中被调用 6 void readFromFile 从文件中读取数据 7 void readyList struct PCB pcb 就绪列表 8 void release struct PCB pcb void releaseR struct PCB pcb 释 放进程 9 void run 执行静态优先级进程调度算法 10 struct PCB runTheProcess 标识要执行的进程 11 void setNewPCB char name int pri int entime int sertime 创建进 程 在 6 中被调用 12 int timeOfData FILE f 计算文件中进程数量 在 6 中被调用 2 3 相关数据结构设计 结构体 struct PCB head readyHead 3 详细设计 3 1 采用 C 语言定义的相关数据类型 struct PCB int ArrivalTime int ServiceTime char number 10 struct PCB head thisP newP 动态接收进程及详细 struct PCB readyHead 动态存储就绪队列 采用结构体数组 创建一个进程 包含进程相关信息 进程名称 进程优 先级 进程到达时间 进程服务时间 精品文档 4欢迎下载 3 2 调度算法的主要实现 struct PCB callMemory 调入内存 返回调入内存的链表节点 将达 到进程进入内存时间的所有进程调入内存 void readyList struct PCB pcb 单链表的形式创建就绪队列 将进入 内存的进程调入就绪列表 struct PCB runTheProcess 执行的进程 返回要执行进程的节点 将就绪列表中满足运行条件的进程标识下来并返回节点 void run 静态优先权算法 将执行的程序释放 调入新的满足执行条 件的进程 就绪列表释放 4 运行结果 4 1 系统调试 在程序设计初期 本想采用冒泡排序将进入内存的进程进行优先级排序 不过最后总是排序失败 最后想到我进行的是进程调度模拟 应该就有进程调 入内存以及调入 CPU 因此之后设计其他函数进行调入内存 CPU 的模拟 而且 最后选择新建就绪列表 进行选择插入就绪列表中 以及随时使用屏幕打印语 句 printf 来测试程序各个阶段执行状态 4 2 功能实现界面 1 主菜单 如图 4 1 所示 精品文档 5欢迎下载 图 4 1 主菜单 2 进程调度模拟 图 4 2 创建进程 2 精品文档 6欢迎下载 图 4 3 进程运行过程 3 进程在调度算法中 计算出的具体的完成时间 周转时间 带权时间 如图 4 4 所示 图 4 4 进程运行结果 3 选择 2 从文件读取数据 如图 4 5 精品文档 7欢迎下载 在 f test txt 中 数据如下 从文件读取数据 数据格式如下 进程名优先级到达时间服务时间 proc12110 proc22111 proc3322 运行结果 如图 4 6 精品文档 8欢迎下载 图 4 6 文件读取数据及运行结果 5 使用说明 根据屏幕提示输入即可 需要用户注意的是优先级 整数表示 越大优先权越大 6 心得体会 本次课程设计 第一天上午去拿课程设计题目采用静态优先权优先算法的进程调度程采用静态优先权优先算法的进程调度程 序序 下午开始查找资料并且构思 在网上看到一些课程设计用到的有数据结构体 struct 便再度拿出 C 语言书本以及数据结构课本 主要看了数据结构体和单链表方面的知识 上 面也曾说到 程序设计初期打算在单链表中直接使用冒泡排序法进程优先级的排序 总是 失败 后来意识到 进程调度不仅要考虑到进程优先级 同时还有进入内存的时间 因为 只有到达进入内存的时间 进程才会被调入内存中 进一步通过满足条件被调入 CPU 中执 行 或者说分配 CPU 进而执行 所以索性模拟出调入内存方法以及调入 CPU 方法 与此有 极大关系的是单链表就绪列表的建立 进行代码编写以及测试 从而模拟进程调度算法完 精品文档 9欢迎下载 成 7 附录 7 1 源代码 include include include int SequenceNumber 1 进程编号 int ProcessAmount 进程数量 int StartCount 0 调入内存进程计数 struct PCB 进程控制块 int No 进程号 char name 16 进程名 int enterMemoryTime 进入内存时间 int serviceTime 服务时间 int priority 优先级 struct PCB next struct PCB head thisP newP 动态接收进程及详细 struct PCB readyHead 动态存储就绪队列 函数声明 int getch int timeOfData FILE void ListAllPCB void Menu void printPCB struct PCB int int int double void printPCBP struct PCB void printField void printFieldP void release struct PCB void releaseR struct PCB void setNewPCB char int int int struct PCB runTheProcess void newPCB 建立 PCB newP struct PCB malloc sizeof struct PCB 精品文档 10欢迎下载 if head NULL 判断头节点是否为空 head newP 为空 头节点指向新开辟的内存 else thisP head while thisP next NULL thisP thisP next thisP next newP 遍历单链表 找到最后一个元素 thisP newP thisP No SequenceNumber SequenceNumber printf 进程号 d n thisP No printf 输入进程名 scanf s thisP name printf 输入优先级 scanf d printf 输入进入内存时间 scanf d printf 输入服务时间 scanf d thisP next NULL void buildProcess 创建进程 int i 0 printf 输入进程数量 scanf d while inext NULL thisP thisP next 精品文档 11欢迎下载 thisP next newP thisP newP strcpy thisP name pcb name thisP No pcb No thisP priority pcb priority thisP enterMemoryTime pcb enterMemoryTime thisP serviceTime pcb serviceTime thisP next NULL struct PCB callMemory 调入内存 返回调入内存的链表节点 int at 到达时间 struct PCB markP if head NULL printf 程序没有找到 n else markP thisP head 标记指向头节点 at thisP enterMemoryTime 到达时间为头节点到达时间 while thisP next NULL 当下一节点不为空 if at thisP next enterMemoryTime 判断当前时间是否大于下一 节点时间 markP thisP next 是 标记此节点 at markP enterMemoryTime 到达时间更改为标记时间 thisP thisP next 向后遍历 return markP void run 静态优先级算法执行 struct PCB temp 临时节点用来存储调入内存节点 struct PCB runPro 用来接收执行的节点 int i 循环初始条件 int at srt runtime 0 到达时间 开始执行时间 运行时间 int turnOverTime 周转时间 double ptot 带权周转时间 if head NULL printf 没有发现进程 n else for i 0 ienterMemoryTime runtime at temp serviceTime turnOverTime runtime at ptot turnOverTime 1 0 temp serviceTime readyList temp 初始纳入就绪列表以及后续 release temp 释放进程 while head NULL runtime runPro serviceTime turnOverTime runtime runPro enterMemoryTime ptot turnOverTime 1 0 runPro serviceTime printf 当前执行的进程 n printField printPCB runPro srt runtime turnOverTime ptot releaseR runPro printf n 就绪进程列表 n ListAllPCB readyHead printf n struct PCB runTheProcess 执行的进程 返回要执行进程的节点 int time pri struct PCB markThis 标记要返回的节点 if readyHead NULL printf 没有可运行的进程 n else markThis thisP readyHead time thisP enterMemoryTime 当前到达时间 pri thisP priority 当前进程的优先级 while thisP next NULL if time thisP next enterMemoryTime 判断之后节点的到达时间是否 与当前一致 if prinext priority 一致 则判断优先级决定 pri thisP next priority 更改优先级判断条件为下一优先级 精品文档 13欢迎下载 markThis thisP next 标记当前节点的下一节点 else break thisP thisP next return markThis void release struct PCB pcb 删除原单链表的进程节点 struct PCB markP f markP head if pcb NULL if pcb head f head head head next free f else thisP head next while thisP NULL if pcb thisP f thisP markP next thisP next free f break else markP thisP thisP thisP next void releaseR struct PCB pcb 删除就绪列表中进程节点 struct PCB markP f markP readyHead if pcb NULL if pcb readyHead f readyHead readyHead readyHead next free f else thisP readyHead next 精品文档 14欢迎下载 while thisP NULL if pcb thisP f thisP markP next thisP next free f break else markP thisP thisP thisP next void ListAllPCB struct PCB h 打印所有进程 printFieldP if h NULL printf 没有进程 n else thisP h while thisP NULL printPCBP thisP thisP thisP next printf n 按任意键继续 n getch printf n n void printPCB struct PCB pcb int a int b int c double d 打印单个数据结果 if pcb NULL printf 8s 8d 8d 8d 8d pcb name pcb No pcb priority pcb enterMemoryTime pcb serviceTime printf 8d 8d 8d 8 2lf n a b c d else printf 没有进程 n void printPCBP struct PCB pcb if pcb NULL printf 8s 8d 8d 8d 8d n pcb name pcb No pcb priority pcb enterMemoryTime pcb serviceTime else printf 没有进程 n 精品文档 15欢迎下载 void printField 打印表头 以及周转时间 printf n printf 进程名 t 进程号 t 优先级 t 到达时 t 服务时 t 开始执 t 完成时 t 周转时 t 带权周 n printf t t t 间 t 间 t 行时间 t 间 t 间 t 转时间 n void printFieldP 打印表头 字段 printf n printf 进程名 t 进程号 t 优先级 t 到达时 t 服务时 n printf t t t 间 t 间 n 从文件读取数据 数据格式如下 进程名优先级到达时间服务时间 proc12110 proc22111 proc3322 void readFromFile FILE fp int times int i 0 char filePath 20 temp 8 char name 16 int pri emt st printf 输入文件路径 scanf s filePath fp fopen filePath r times timeOfData fp ProcessAmount times 2 while inext NULL thisP thisP next thisP next newP thisP newP thisP No SequenceNumber SequenceNumber strcpy thisP name name thisP priority pri thisP enterMemoryTime entime thisP serviceTime sertime thisP nex
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年文化创意产业园区品牌塑造与产业集聚的产业园区品牌战略规划
- 2025年智能交通系统在高速公路智能交通系统车联网与智能物流中的应用报告
- 2025年教育信息化基础设施建设:教育信息化产业创新趋势报告
- 信贷工作计划范文
- 江苏省苏州市2026届高三上学期期初阳光调研英语试卷(含音频)
- 《家具购买合同》模板
- 幽默安全培训讲义课件
- 巡察组联络员经验课件
- 岩石与矿物课件
- 输煤班组安全培训内容课件
- 地方病防治技能竞赛试题及答案
- 2025年秋期新课标人教版六年级上册数学全册教案(核心素养教案)
- 高职考试管理办法
- 福州市晋安区社区工作者招聘笔试真题2024
- 2025年半导体制造用胶膜市场调查报告
- 家长学校亲子沟通课件
- 超声科主任竞聘演讲稿
- 工地工伤预防培训
- 辽宁省2022-2024年中考满分作文134篇
- (完整)夏季防暑降温教育培训试题及答案
- 复卷机安全操作规程
评论
0/150
提交评论