ImageVerifierCode 换一换
格式:DOCX , 页数:15 ,大小:78.94KB ,
资源ID:11661474      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/11661474.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实验报告材料一进程调度算法.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实验报告材料一进程调度算法.docx

1、实验报告材料一进程调度算法江西师范大学计算机信息工程学院学生实验报告专业 12级物联网班 姓名 严超 学号 1208067042 日期 2014/05/8 课程名称操作系统教程实验室名称W4313实验名称进程调度算法指导教师张练兴成绩1、实验目的用代码实现模拟操作系统的进程调度,以加深对进程的概念及进程调度算法的理解2、实验原理和内容(1)先来先服务(FCFS)调度算法:从“就绪队列”中选择一个最先进入队列的进程,为它分配处理器,使之开始运行。(2)优先数调度算法:根据进程的情况或要求赋予进程一个优先级,进程运行过程中优先级不再改变。每次调度时,就绪队列中优先级最高的进程被率先调度,同级的采用

2、先来先服务(FCFS)。3、实验步骤进程调度算法:(1)编写进程控制块数据结构(2)统一按照FCFS调度算法创建队列(3)在FCFS调度算法中,将就绪队列队首进程调入执行,如果在队列中存在到达时间小于等于当前时间的结点,将该结点的状态设为就绪状态。如果当前进程执行完了,就将其状态改为完成状态,并将其插入到队尾。(4)在优先级调度算法中,将就绪队列队首进程调入执行,如果在队列中存在到达时间小于等于当前时间的结点,将该结点的状态设为就绪状态,并对队列中的结点按优先级数的大小进行排序(队首除外)。如果当前进程执行完了,就将其状态改为完成状态,并将其插入到队尾。(5)输出运行后的结果,如周转时间和带权

3、周转时间。4、程序及运行结果(或实验数据记录及分析)进程调度算法: 本次实验让我更加明白进程调度的概念,更加了解进程调度的工作原理。在前期,我是直接将结果显示出来,后来,我又在原有的基础上加了显示每一时刻队列的信息。在编写此代码过程中遇到很多问题,例如指针问题,指针指来指去,总是指错地址。具体代码:#include#include#define MAX 1000typedef struct progress int ID; /进程名 char state; /进程状态 int super; /优先数 int arrive_time; /到达时间 int serve_time; /服务时间 st

4、ruct progress *next;node;node* sortFCFS(node* head,node* q) node *p,*pre; int done=0; if(head=NULL)|(q-arrive_time)arrive_time) /*到达时间最先者,插入队首*/ q-next=head; head=q; else /* 进程比较到达时间,插入适当的位置中*/ p=head; pre=p-next; while(pre!=NULL) if(q-arrive_time)arrive_time) /*若插入进程比当前进程到达时间小,*/ /*插入到当前进程前面*/ q-ne

5、xt=pre; p-next=q; pre=NULL; done=1; else p=p-next; pre=pre-next; if(done=0) p-next=q; return head;/*函数功能:创建单链表参数:空返回值:指向节点的指针head */node* create() node *head; node *p,*q; int x,count=0; head=NULL; printf(ntt请输入进程名【输入-1结束】:); while(scanf(%d,&x)!=EOF & x!= -1) p=(node *)malloc(sizeof(node); printf(tt请

6、输入优先级数【优先数高者优先】:); scanf( %d,&p-super); printf(tt请输入到达时间【到达时间不得小于0】:); scanf( %d,&p-arrive_time); printf(tt请输入服务时间【服务时间必须大于0】:); scanf( %d,&p-serve_time); p-ID=x; p-state=w; p-next=NULL; head=sortFCFS(head,p); printf(ntt请输入进程名(输入-1结束):); return head;/*函数功能:输出单链表参数:指向节点的指针head返回值:空*/void print(node *

7、head) node *p; printf(nt|-结点信息情况-|); printf(ntt| 进程名 |优先级数|到达时间|服务时间| 状态 |); p=head; while(p) printf(ntt|%8d|%8d|%8d|%8d|%8c|,p-ID,p-super,p-arrive_time,p-serve_time,p-state); p=p-next; printf(nt|-结点信息情况-|n);/*函数功能:利用先来先服务调度算法 参数:指向节点的指针head返回值:空存在问题: */void FCFS(node* head) int start_time,finish_ti

8、me=0,round_time,all_time=0; int done=1; int clock=0; float right_round_time; node* p,*q,*flag; flag=p=head; clock=p-arrive_time; all_time=start_time=head-arrive_time; while(p) all_time+=p-serve_time; p=p-next; p=head; while(done) done=0; printf(nnt|-第%2d 时刻-|,clock); while(p) if(p-arrive_timestate=w

9、|p-state=r) p-state=r;done=1; p=p-next; while(flag-next)flag=flag-next; print(head); printf(t|-第%2d 时刻-|nn,clock); if(clock=all_time)break; clock+; finish_time=start_time+head-serve_time; if(finish_time=clock) head-state=f; flag-next=head; head=head-next; flag=flag-next; flag-next=NULL; start_time=f

10、inish_time; p=head; p=head; finish_time=p-arrive_time; printf(t|-FCFS调度算法-|); printf(nt| 进程名 |到达时间|服务时间|开始时间|完成时间|周转时间|带权周转|); while(p) if(p-arrive_timearrive_time; finish_time=start_time+p-serve_time; round_time=finish_time-p-arrive_time; right_round_time=(float)round_time/p-serve_time; printf(nt|%

11、8d|%8d|%8d|%8d|%8d|%8d|%8.2f|,p-ID, p-arrive_time,p-serve_time,start_time,finish_time,round_time,right_round_time); p=p-next; printf(nt|-FCFS调度算法-|); printf(n); void SortBySuper(node *head) node *p1,*q1,*temp; temp=(node*)malloc(sizeof(node); for(p1=head-next;p1!=NULL&p1-state=r;p1=p1-next) for(q1=p

12、1-next;q1!=NULL&q1-state=r;q1=q1-next) if(p1-supersuper) temp-ID=p1-ID; p1-ID=q1-ID; q1-ID=temp-ID; temp-super=p1-super; p1-super=q1-super; q1-super=temp-super; temp-arrive_time=p1-arrive_time; p1-arrive_time=q1-arrive_time; q1-arrive_time=temp-arrive_time; temp-serve_time=p1-serve_time; p1-serve_ti

13、me=q1-serve_time; q1-serve_time=temp-serve_time; temp-state=p1-state; p1-state=q1-state; q1-state=temp-state; /*函数功能:利用优先数调度算法 参数:指向节点的指针head返回值:空存在问题:*/void priority(node* head) int start_time,finish_time=0,round_time,all_time=0; int done=1; int clock=0; float right_round_time; node* p,*q,*flag; fl

14、ag=p=head; clock=p-arrive_time; all_time=start_time=head-arrive_time; while(p) all_time+=p-serve_time; p=p-next; p=head; while(done) done=0; printf(nnt|-第%2d 时刻-|,clock); while(p) if(p-arrive_timestate=w|p-state=r) p-state=r;done=1; p=p-next; SortBySuper(head);while(flag-next)flag=flag-next; print(h

15、ead); printf(t|-第%2d 时刻-|nn,clock); if(clock=all_time)break; clock+; finish_time=start_time+head-serve_time; if(finish_time=clock) head-state=f; flag-next=head; head=head-next; flag=flag-next; flag-next=NULL; start_time=finish_time; p=head; p=head; finish_time=p-arrive_time; printf(nt|-优先数调度算法-|); p

16、rintf(nt| 进程名 |到达时间|服务时间|开始时间|完成时间|周转时间|带权周转|); while(p) if(p-arrive_timearrive_time; finish_time=start_time+p-serve_time; round_time=finish_time-p-arrive_time; right_round_time=(float)round_time/p-serve_time; printf(nt|%8d|%8d|%8d|%8d|%8d|%8d|%8.2f|,p-ID, p-arrive_time,p-serve_time,start_time,finis

17、h_time,round_time,right_round_time); p=p-next; printf(nt|-优先数调度算法-|); printf(n);int main() char choice; node *head; do printf(ntt|-MUNE-|n); printf(tt|-1.FCFS调度算法-|n); printf(tt|-2.优先数调度算法-|n); printf(ttt你的选择是:bb); while(scanf( %c,&choice)!=EOF&choice!=1&choice!=2); head=create(); switch(choice) case 1:print(head); FCFS(head);break; case 2:print(head); priority(head);break; 运行结果截图:先来先服务调度算法运行结果优先级调度算法运行结果

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1