




已阅读5页,还剩14页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
郑州轻工业学院本科实验报告设计题目: FPF与RR 学生姓名: 郭宇宁 系 别: 计算机与通信工程学院 专 业: 网络运维 班 级: 13-03 学 号: 521507110307 指导教师: 吉星、程立辉 2015 年 11月25 日#include stdio.h#include stdlib.h#include iostream.h#define NULL 0#define false 0#define true 1bool _state=0;struct PCBint ID;int priority;int CPUtime;int ALLtime;int State;PCB* next;void init(); /*产生idle进程,输入用户进程数目,调用insert()*/void print(PCB *pcb); /*输出进程属性信息*/void print_init(PCB *pcb);/*输出所有PCB的初始值*/void insert(); /*生成进程属性信息,插入进程就绪队列*/void Run_priority(PCB *pcb); /*运行进程,随机阻塞进程、产生新进程,插入就绪队列,唤醒阻塞进程*/void block(PCB *pcb); /*调用destroy()将进程插入阻塞队列*/void wakeup(); /*唤醒进程,插入就绪队列*/void proc_priority();/*优先权调度算法模拟*/void proc_loop(); /*轮转法调度算法模拟*/void update(PCB *pcb); /*更新进程信息*/void pushback_queue(PCB *queue,PCB *item); /*将item插入到队列的尾部*/void insert_queue(PCB *queue,PCB *item); /*将item插入到队列中,使得插入后,队列中按照优先级从高到低有序*/void sort_queue(PCB *&queue); /*对queue中的结点进行排序,按照优先级从大到小*/PCB *ready_queue,*block_queue,*idleprocess; /*就绪队列,阻塞队列及闲逛进程指针变量*/int main(int argc, char* argv)int i=0;while(1)cout*PROCESS*/;cout(n Please select a num in(1,2,0) );cout(n 1 - priority );cout(n 2 - loop );cout(n 0 - exitn);cout- ;coutendl; couti;while(i)if(i=1)cout(nThis is a example for priority processing ! n );init();proc_priority();else if (i=2)cout(nThis is a example for round robin processing ! n );init();proc_loop();elsecoutPlease select a num in(1,2,0)!n;couti;return 0;/输出所有PCB的初始值void print_init(PCB *pcb)PCB* temp=pcb-next ;cout(nID priority CPUtime ALLtime State);while(temp!=NULL)coutnID priority CPUtime ALLtime;if(temp-State=0)coutState =1)cout( running);elsecoutnext;/输出进程属性信息void print(PCB *pcb)PCB *temp;temp=pcb;if(pcb-ID=0)cout(nThe idle peocess id running!);elsecoutnID priority CPUtime ALLtime;if(temp-State=0)coutState =1)cout( running);elsecoutnext;while(p!=0&p-priority=item-priority)q=p;p=p-next;if(p=0)item-next =0;q-next=item;elseitem-next =p;q-next =item;/将item插入到阻塞队列的尾部void pushback_queue(PCB *queue,PCB *item)PCB *p,*q;q=queue,p=q-next;while(p!=0)q=p;p=p-next;item-next =q-next ;q-next =item;/对queue中的结点进行排序,按照优先级从大到小void sort_queue(PCB *&queue)PCB *temp=new PCB;temp-next =0;while(queue-next )PCB *p;p=queue-next;queue-next =p-next ;insert_queue(temp,p);queue-next =temp-next ;delete temp;/生成进程属性信息,插入进程就绪队列,显示进程信息void insert()PCB *newp=0;static long id =0;newp=new PCB;id+;newp-ID =id;newp-State=0;newp-CPUtime=0;newp-priority=rand()%3+1;newp-ALLtime=rand()%3+1;newp-next =NULL;pushback_queue(ready_queue,newp);/print(newp);/cout readyn);/生成n个进程属性信息,插入进程就绪队列,显示进程信息void insert(int n)for(int i=0;inext=0;ready_queue=new PCB;ready_queue-next=0;int i=0,pcb_number=-1;/闲逛进程放入就绪队列idleprocess=NULL;idleprocess=(PCB *)malloc(sizeof(PCB);idleprocess-ID=0;idleprocess-State=0;idleprocess-CPUtime=0;idleprocess-priority=0;idleprocess-ALLtime=0;idleprocess-next=NULL;idleprocess-next=ready_queue-next;/闲逛进程放入就绪队列ready_queue-next=idleprocess;/也可以假定初始时系统中只有一个idle进程/输入初始进程的个数 while(pcb_number0)coutpcb_number;cout(nID priority CPUtime ALLtime Staten);for(;ipcb_number;i+)insert();cout就绪队列初始化成功!endl;:print_init(ready_queue);coutState=2;pcb-CPUtime-=2;if(pcb-CPUtimeCPUtime+=2;coutnThe process noID is blocked!;print(pcb);cout blockedn);pcb-next=block_queue-next;block_queue-next =pcb;/更新进程信息,就绪队列中进程的优先级均增加1void update(PCB *pcb)PCB *temp=pcb-next;while(temp&temp-next )temp-priority+;temp=temp-next;/唤醒进程,插入就绪队列void wakeup()if(block_queue-next=0)/*此时没有阻塞的进程,无所谓的唤醒*/return ;PCB *q,*p;while(true)q=block_queue;p=q-next;while(p&rand()%20!=1)q=p;p=p-next;if(p!=0)q-next =p-next ;break;p-State=0;coutendl;print(p);cout readyID=0)insert_queue(ready_queue,pcb);print(pcb);cout runningn;elsepcb-State=1;pcb-CPUtime+=4;pcb-priority=pcb-priority -3;/*每运行一个时间片,其优先数减3*/if(pcb-priority priority=1;print(pcb);printf(变迁1: ready - runningn);if(rand()%3=1)/*PCB不是闲逛进程,满足条件侧阻塞此进程*/if(pcb-CPUtime-2ALLtime)block(pcb);else/*已执行完毕,应该销毁进程*/coutn;coutThe process noIDDestroyCPUtime=pcb-ALLtime)/*释放*/coutn;coutThe process no ID DestroryID=0)insert_queue(ready_queue,pcb);print(pcb);cout runningn;elsepcb-State=1;pcb-CPUtime=pcb-ALLtime;print(pcb);printf(变迁1: ready - runningn);if(rand()%3=1)/*PCB不是闲逛进程,满足条件侧阻塞此进程*/_state=1;block(pcb);elsecoutn;coutThe process no ID Destroryendl;delete pcb;if(rand()%5=1)insert(3);if(rand()%7=1)wakeup();/优先权调度算法模拟void proc_priority()sort_queue(ready_queue);PCB *temp=0,*running=0;int times=0;coutn调度前:;:print_init(ready_queue);for(;timesnext;ready_queue-next =running-next ;coutendl;coutn调度开始:endl;Run_priority(running);coutn本次调度结束。endl;/轮转调度算法模拟void proc_loop()PCB *temp=0,*running=0;int times=10;coutnext;ready_queue-next =running-next ;cout0)times=times-running-ALLtime;/每次运行一个进程减去ALLtime;if(times=0)Run_loop(running);else if(_state)/如果运行时被阻塞,则运行2个时间单位times=times+2;_state=0;cout5487584574389574 fgfgfgfgf gfgfg38954378954375894378954375;elsepushback_queue(block_queue,running);/时间不过,则阻塞该进程,放到阻塞队列else if(times=0)coutn本次调度时间片到!;break;coutn本次调度结束。endl;优先权调度(1)输入1选择优先权调度算法模拟。(2)输入开始进程个数n,创建n个PCB并加入就绪队列ready_queue中。(3)就绪队列ready_queue不为空,调度就绪队列中第一个进程运行,否则,从闲逛队列idleprocess中调度闲逛进程运行。(4)在运行过程中,当遇到阻塞,则该进程插入到阻塞队列block_queue中,且将该进程从ready_queue中删除。(5)如果运行时间CPUtime大于等于Alltime,该进程运行完毕,释放该进程;否则插入到就绪队列中。(6)更新就绪队列中的优先级数。(7)随机对阻塞队列block_queue中的进程PCB询问是否要唤醒,唤醒,即从唤醒队列中选择第一个进程,且插入就绪队列中;阻塞队列中没有阻塞进程返回。(8)重复上述步骤,直到本次调度结束。时间片轮转调度(1)输入2选择优先权调度算法模拟。(2)输入开始进程个数n,创建n个PCB并加入就绪队列ready_queue中。(3)就绪队列ready_queue不为空,调度就绪队列中第一个
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 氢能碳减排潜力-洞察及研究
- 2025年事业单位工勤技能-重庆-重庆军工电子设备制造工三级(高级工)历年参考题库含答案解析
- 2025年事业单位工勤技能-贵州-贵州政务服务办事员一级(高级技师)历年参考题库含答案解析
- 2025年事业单位工勤技能-贵州-贵州信号工-机车信号设备维修四级(中级工)历年参考题库含答案解析
- 2026届湖北省高中联考化学高一上期中考试试题含解析
- 福州第三中学2026届高三化学第一学期期中质量跟踪监视试题含解析
- 2026届湖南省市衡阳第八中学高一化学第一学期期中综合测试模拟试题含解析
- Unit6SectionB(1a-1e)教案人教版八年级英语上册
- 10. 汽车融资租赁合同书示范文本
- 新解读《GB-T 35860-2018气体分析 校准用混合气体证书内容》
- 新版中国电信员工手册
- 2023年中国工商银行软件开发中心春季校园招聘500人笔试模拟试题及答案解析
- 地质勘查钻探岩矿心管理通则
- D500-D505 2016年合订本防雷与接地图集
- 中国重症加强治疗病房(ICU)建设与管理指南
- 社区矫正法课件
- 后勤保障楼幕墙施工方案新
- GB/T 19326-2022锻制支管座
- GB/T 8949-2008聚氨酯干法人造革
- GB/T 30544.1-2014纳米科技术语第1部分:核心术语
- GB 12982-2004国旗
评论
0/150
提交评论