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

下载本文档

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

文档简介

1、精选优质文档-倾情为你奉上学号E 专业计算机科学与技术 姓名施飞宇实验日期2018/10/25 教师签字 成绩实验报告【实验名称】 进程调度【实验目的】巩固和加深处理机调度的概念。设计调度算法,模拟实现处理机的调度【实验原理】先来先服务(FCFS)调度算法FCFS是最简单的调度算法,该算法既可用于作业调度,也可用于进程调度。 当在作业调度中采用该算法时,系统将按照作业到达的先后次序来进行调度,或者说它是优先考虑在系统中等待时间最长的作业,而不管该作业所需执行时间的长短,从后备作业队列中选择几个最先进入该队列的作业,将它们调入内存,为它们分配资源和创建进程,然后把它放入就绪队列。【实验内容】本次

2、实验进程的数据结构如下:typedef struct pcbchar pnameN;/进程名int runtime;/运行时间int arrivetime;/到达时间int starttime;/开始运行时间 float avgtime;/带权周转时间char state;/进程状态 struct pcb *next;/链表指针PCB;1. 设计先来先服务调度算法FCFS测试数据:算法流程图(图1):图1源代码:/*2018/10/26 施飞宇 笃行南楼a202*/#define N 20#include <iostream>#include <stdlib.h>usi

3、ng namespace std;typedef struct pcbchar pnameN;/进程名int runtime;/运行时间int arrivetime;/到达时间int starttime;/开始运行时间 float avgtime;/带权周转时间char state;/进程状态 struct pcb *next;/链表指针PCB;PCB headinput;PCB headrun;PCB * pcbinput;void inputprocess();/建立进程函数int readydata()return 1;/判断进程是否进入就绪函数void runprocess();/运行

4、进程函数void inputprocess()PCB *p1,*p2;cout<<"输入进程数目"<<endl;int num;cin>>num;int i=0;p1=&headinput;p2=p1;for(i=0;i<num;i+)cout<<"输入第"<<i+1<<"进程名,运行时间,到达时间"<<endl; scanf("%s",p1->pname);cin>>p1->runtime;c

5、in>>p1->arrivetime;p1->next=new PCB;p2=p1;p1=p1->next;delete p1;p1=NULL;p2->next=NULL;void runprocess()PCB *p1;int time=0;/时间p1=&headinput;printf("进程名到达时间服务时间开始执行时间完成时间周转时间带权周转时间n");while(p1!=NULL)if(time<p1->starttime)time=p1->starttime;p1->starttime=time

6、; p1->avgtime=(p1->starttime+p1->runtime-p1->arrivetime)*1.0/p1->runtime;time=p1->starttime+p1->runtime; printf("%s %10d %10d %10d %10d %10d %5fn",p1->pname,p1->arrivetime,p1->runtime,p1->starttime,p1->starttime+p1->runtime,p1->starttime+p1->run

7、time-p1->arrivetime,p1->avgtime); p1=p1->next;int main()inputprocess(); runprocess();return 0;运行截图:2. 设计按短进程优先调度算法SJF测试数据:算法流程图(图2):是否图2源代码:/*2018/10/26 施飞宇 笃行南楼a202*/#define N 20#include <iostream>#include <stdlib.h>#include <stdio.h>using namespace std;typedef struct pcb

8、char pnameN;/进程名int runtime;/运行时间int arrivetime;/到达时间int starttime;/开始运行时间 float avgtime;/带权周转时间char state;/进程状态 struct pcb *next;/链表指针PCB;PCB headinput;PCB headrun;PCB * pcbinput;void inputprocess();/建立进程函数int readydata()return 1;/判断进程是否进入就绪函数void runprocess();/运行进程函数void inputprocess()PCB *p1,*p2;

9、cout<<"输入进程数目"<<endl;int num;cin>>num;int i=0;p1=&headinput;p2=p1;for(i=0;i<num;i+)cout<<"输入第"<<i+1<<"进程名,到达时间,运行时间"<<endl; scanf("%s",p1->pname); cin>>p1->arrivetime;cin>>p1->runtime; p1-&g

10、t;state='a'p1->next=new PCB;p2=p1;p1=p1->next;delete p1;p1=NULL;p2->next=NULL;void runprocess() int b;PCB *p1,*p2;int time=0;/时间int runtime=0;/存储运行最短时间int label;printf("进程名到达时间服务时间开始执行时间完成时间周转时间带权周转时间n");while(1) runtime=100; p1=&headinput; label=1; while(p1!=NULL) if(

11、p1->state!='a') p1=p1->next; continue; else / cin>>b; if(runtime>p1->runtime)&&(time>=p1->arrivetime) p2=p1; runtime=p1->runtime;/ printf("%s %dn",p1->pname,runtime); label=0; p1=p1->next; if(label) break; p2->state='b'p2->star

12、ttime=time; p2->avgtime=(p2->starttime+p2->runtime-p2->arrivetime)*1.0/p2->runtime;time=p2->starttime+p2->runtime; printf("%s %10d %10d %10d %10d %10d %15.5fn",p2->pname,p2->arrivetime,p2->runtime,p2->starttime,p2->starttime+p2->runtime,p2->starttime+p2->runtime-p2->arrivetime,p2->avgtime);int main()inputprocess();PCB *p2=&headinput;/while(p2)/ printf("%s %10d %10d %10d %10d %10d %5fn",p2->pname,p2->arrivetime,p2->runtime,p2->starttime,p2->startt

温馨提示

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

评论

0/150

提交评论