![时间片轮转调度算法 RR_第1页](http://file4.renrendoc.com/view/cbcb3c65ea3a427743445e135be65f4a/cbcb3c65ea3a427743445e135be65f4a1.gif)
![时间片轮转调度算法 RR_第2页](http://file4.renrendoc.com/view/cbcb3c65ea3a427743445e135be65f4a/cbcb3c65ea3a427743445e135be65f4a2.gif)
![时间片轮转调度算法 RR_第3页](http://file4.renrendoc.com/view/cbcb3c65ea3a427743445e135be65f4a/cbcb3c65ea3a427743445e135be65f4a3.gif)
![时间片轮转调度算法 RR_第4页](http://file4.renrendoc.com/view/cbcb3c65ea3a427743445e135be65f4a/cbcb3c65ea3a427743445e135be65f4a4.gif)
![时间片轮转调度算法 RR_第5页](http://file4.renrendoc.com/view/cbcb3c65ea3a427743445e135be65f4a/cbcb3c65ea3a427743445e135be65f4a5.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include#include#define MAX 5进程数量#define RR 1时间片大小/*时间片轮转算法*/struct proint num;int arriveTime;int burst;int rt;记录进程被运行的次数struct pro *next;int TOTALTIME; 记录所有进程的总时间/函数声明struct pro* creatList();void insert(struct pro *head,struct pro *s);struct pro* searchByAT(struct pro *head,int AT);void del(struct
2、pro* p);int getCount(struct pro *head,int time);struct pro* searchEnd(struct pro *head);void move(struct pro *headF,struct pro *headT,int n);struct pro* creatList()创建链表,按照进程的到达时间排歹U,记录所有进程的信息struct pro* head=(struct pro*)malloc(sizeof(struct pro);head-next=NULL;struct pro* s;int i;TOTALTIME=0;for(i=
3、0;inum);printf(请输入到达时间:n);scanf(%d,&(s-arriveTime);printf(-请输入运行时间:n);scanf(%d,&(s-burst);TOTALTIME+=s-burst; 计算总时间s-rt=1;/rt的初始值为1s-next=NULL;insert(head,s);return head;到达队列中的进程按照其到达时间的先后顺序排列void insert(struct pro *head,struct pro *s)插入节点struct pro *p=searchByAT(head,s-arriveTime);s-next=p-next;p-n
4、ext=s;return;struct pro* searchByAT(struct pro *head,int AT) 查找第一个到达时间大于等于 AT 的节点,返回其前一个指针struct pro *p,*q;p=head;q=head-next;while(q!=NULL&q-arriveTimenext;return p;void del(struct pro* p)删除 p 的下一个节点struct pro *tmp;tmp=p-next;p-next=tmp-next;free(tmp);return;int getCount(struct pro *head,int time)察
5、看在time之前到达但未移动到运行队列的进程数量int count=0;struct pro *s,*t;s=head;t=s-next;while(t!=NULL&t-arriveTimenext;count+;/count记录当前时刻到达的进程数return count;struct pro* searchEnd(struct pro *head)查找并返回循坏队列的尾节点的前一个节点struct pro *p,*q;p=head;q=head-next;while(q-next!=head)p=q;q=q-next;return p;void move(struct pro *headF
6、,struct pro *headT,int n) 将 headF 后的 n 个节点移动到循环队列headT中struct pro *r,*s,*t;s=headF;t=s-next;r=t;/r记录要移动的第一个节点while(n1)t=t-next;n-;s-next=t-next;以上完成从原队列中摘除相关节点r,t分别为第一个和最后一个节点s=searchEnd(headT);t-next=s-next;s-next=r;void run(struct pro *head)int time=0;记录当前时间int newarrive;/新 到达进程数struct pro *runhea
7、d=(struct pro*)malloc(sizeof(struct pro);runhead-next=runhead;创建新的循环链表,存放当前就绪队列中的进程struct pro *p,*q;p=runhead;q=p-next;/q记录当前应当运行的进程while(time0)move(head,runhead,newarrive);/将 head 后的 newarrive 个节点移动至U runhead 队列I中if(runhead-next=runhead)就绪队列中没有进程time+;else if(q=runhead)p=q;q=q-next;elseprintf(进程名:d
8、n,q-num);printf(到达时间:dn,q-arriveTime);if(q-rt=1)printf(响应时间:dn,time-q-arriveTime);elseprintf(第d 次运行开始时间:dn,q-rt,time); if(q-burstburst;printf(第d 次运行结束时间:dn,q-rt,time);printf(周转时间:dn,time-q-arriveTime);n);n);printf(struct pro *tmp=q;q=q-next;p-next=q;free(tmp);else /q-burstRRtime+=RR;printf(第d 次运行结束时
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 个人调休申请书
- 课题立项申请书选题
- 建筑公司转正申请书
- 电子工业中的高强度紧固件技术探讨
- 小学音乐教学工作总结【15篇】
- 2024-2025学年高中英语Unit1Livingwell单元加餐练新人教版选修7
- 2024-2025学年高中数学第3章统计案例1回归分析学案北师大版选修2-3
- 2024-2025学年高中物理第二章力第3节弹力课时作业含解析教科版必修1
- 科长转正申请书
- 发票专用章申请书
- 2025年电力铁塔市场分析现状
- GB 12158-2024防止静电事故通用要求
- 《教育强国建设规划纲要(2024-2035年)》全文
- 山东省滨州市2024-2025学年高二上学期期末地理试题( 含答案)
- 体育老师篮球说课
- 化学-江苏省苏州市2024-2025学年2025届高三第一学期学业期末质量阳光指标调研卷试题和答案
- 蛋鸡生产饲养养殖培训课件
- 运用PDCA降低住院患者跌倒-坠床发生率
- 海底捞员工手册
- 2024CSCO小细胞肺癌诊疗指南解读
- 立春气象与生活影响模板
评论
0/150
提交评论