操作系统实验九_第1页
操作系统实验九_第2页
操作系统实验九_第3页
操作系统实验九_第4页
操作系统实验九_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上学号E 专业计算机科学与技术 姓名施飞宇实验日期2018/12/20 教师签字 成绩实验报告【实验名称】最低松弛度优先调度算法【实验目的】1. 学习最低松弛度算法思想。2. 用代码实现改算法,解决最低松弛度优先调度问题。【实验原理】最低松弛度优先(LLF)算法是根据任务紧急(或松弛)的程度,来确定任务的优先级。任务的紧急程度愈高,为该任务所赋予的优先级就愈高,使之优先执行。在实现该算法时要求系统中有一个按松弛度排序的实时任务就绪队列,松弛度最低的任务排在队列最前面,被优先调度。松弛度的计算方法如下: 任务的松弛度=必须完成的时间-其本身的运行时间-当前时间&

2、#160;其中其本身运行的时间指任务运行结束还需多少时间,如果任务已经运行了一部分,则: 任务松弛度=任务的处理时间-任务已经运行的时间 当前时间【实验内容】数据结构:本实验进程采用结构体来存储线信息,采用结构体数组来存储进程序列。进程结构定义如下:typedef structint start;/进程申请服务开始时间int over;/进程截止时间int survey1;/需要服务总时间int survey2;/已经服务时间int songchi;/松弛度int label;/等于0未被处理,等于1已经被处理完毕pcb;程序流程图:程序代码:%2018/12/20 笃行南楼 A20

3、2 E 施飞宇#include "iostream"#include <stdio.h>using namespace std;typedef structint start;/进程申请服务开始时间int over;/进程截止时间int survey1;/需要服务总时间int survey2;/已经服务时间int songchi;/松弛度int label;/等于0未被处理,等于1已经被处理完毕pcb;void pcb_A(pcb * A,int n)/A进程创建函数 int i; for(i=0;i<n+1;i+) Ai.start=i*20; Ai.s

4、urvey2=0; Ai.label=0; Ai.songchi=10; Ai.survey1=10; Ai.over=Ai.start+20; if(i!=n) cout<<"A"<<i+1<<"到达时间"<<Ai.start<<" 截止时间"<<Ai.over<<endl; void pcb_B(pcb * B,int n)/B进程创建函数 int i; for(i=0;i<n+1;i+) Bi.start=i*50; Bi.survey2=

5、0; Bi.label=0; Bi.songchi=25; Bi.survey1=25; Bi.over=Bi.start+50; if(i!=n) cout<<"B"<<i+1<<"到达时间"<<Bi.start<<" 截止时间"<<Bi.over<<endl; int test(pcb *X,int n,int time) int i,j; for(i=0;i<n;i+) if(Xi.label=0&&Xi.start<

6、=time) Xi.songchi=Xi.over-(Xi.survey1-Xi.survey2)-time; return i; return -1;void run_AB(pcb *A,int n1,pcb *B,int n2) int time; int ai,bi,ka,kb; int max_time; int AB=1; int label=0; if(n1*20>=n2*50) max_time=n1*20; else max_time=n2*50; cout<<"时间 "<<" A"<<"

7、;截止时间 "<<" 服务时间 "<<" 松弛度 "<<"B 截止时间 "<<" 服务时间 "<<" 松弛度 "<<endl; cout<<"0"<<" A"<<"1"<<" "<<A0.over<<" "<<A0.survey2&l

8、t;<" "<<A0.songchi<<" B"<<"1"<<" "<<B0.over<<" "<<B0.survey2<<" "<<B0.songchi<<endl; for(time=0;time<=max_time;time=time + 1) ka = test(A,n1,time); if(ka = -1) ai=ai+1; else

9、ai=ka; / cout<<"A"<<ai+1<<" "<<Aai.songchi<<endl; kb=test(B,n2,time); if(kb=-1) bi=bi+1; else bi=kb; / cout<<"B"<<bi+1<<" "<<Bbi.songchi<<endl; if(Bbi.songchi=0|ka=-1|label=1) AB=0;label=0; if(Aai.son

10、gchi=0|kb=-1|label=2) AB=1;label=0; if(AB=1&&ai<n1) if(Aai.survey1=(+Aai.survey2) cout<<time+1<<" A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1

11、<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; cout<<time+1<<" A"<<ai+1<<"进程结束"<<endl; Aai.label=1; label=1; else if(time+1)%5=0) cout<<time+1<<"

12、 A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<

13、<endl; if(AB=0&&bi<n2) if(Bbi.survey1=(+Bbi.survey2) cout<<time+1<<" A"<<ai+1<<" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<&

14、lt;Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; cout<<time+1<<" B"<<bi+1<<"进程结束"<<endl; Bbi.label=1; label=2; else if(time+1)%5=0) cout<<time+1<<" A"<<ai+1<&l

15、t;" "<<Aai.over<<" "<<Aai.survey2<<" "<<Aai.songchi/5*5<<" B"<<bi+1<<" "<<Bbi.over<<" "<<Bbi.survey2<<" "<<Bbi.songchi/5*5<<endl; if(kb=-1) bi=bi-1; if(ka=-1) ai=ai-1; int main() int n1,n2; pcb A10,B10; cout<<"输入A进程个数"<<

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论