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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

进程调度 实验报告.docx

1、进程调度 实验报告实验一 进程调度 实验报告一、实验目的多道程序设计中,经常是若干个进程同时处于就绪状态,必须依照某种策略来决定那个进程优先占有处理机。因而引起进程调度。本实验模拟在单处理机情况下的处理机调度问题,加深对进程调度的理解。二、实验内容1优先权法、轮转法简化假设1)进程为计算型的(无I/O)2)进程状态:ready、running、finish3)进程需要的CPU时间以时间片为单位确定2算法描述1)优先权法动态优先权当前运行进程用完时间片后,其优先权减去一个常数。2)轮转法三、流程图四、实验要求1产生的各种随机数的取值范围加以限制,如所需的CPU时间限制在120之间。2进程数n不要

2、太大通常取48个3使用动态数据结构4独立编程5至少三种调度算法6若有可能请在图形方式下,将PCB的调度用图形成动画显示。五 实验源程序主函数 控制台Main.c#include #include#include fcfs.h#include privilege.h#include round.hvoid main() int n; cout输入随机产生的进程数目n; int choice=1; while (choice!=5) cout请输入你的选择endl; cout1:FCFS调度算法n2:动态优先权调度算法n3:时间片轮转法n4:清屏n5:退出choice; switch (choic

3、e) case 1: struct process *first=creatlist(n);print(first);fcfs(first);break; case 2: struct process1 *first1=creatlist1(n);print1(first1);privilege(first1);break; case 3:struct process2 *first=creatlist2(n);print2(first);round(first);break; case 4: system(cls);break; case 5: break; default: break;

4、/*/先来先服务调度算法:fcfs.h#ifndef FCFS_H#define FCFS_H#include#include#include#include#include #define random(x) (rand()%x)struct process int num; /进程号 int attime,servtime; /进程到达时间,服务时间 process *next; ;struct process*creatlist(int); /新建一个链表void insert(struct process *first,struct process *s); /插入一个节点(尾插法)v

5、oid print(struct process *first); /打印函数struct process*creatlist(int n) srand(int)time(0); struct process*first=new process; first-next=NULL; for (int i=0;inum=i; s-attime=i; s-servtime=random(20); insert(first,s); return first;void insert(struct process *first,struct process *s) struct process *r=fi

6、rst; struct process *p; while(r)p=r;r=r-next; p-next=s;p=s; p-next=NULL;void print(struct process *first) /打印函数 struct process *p; p =first-next; cout随机产生的进程的信息如下endl; cout进程名 进程到达时间 进程服务时间endl; while (p) coutnumtattimesetw(14)servtimenext; void fcfs(struct process *first) int startime=0;/开始执行时间 int

7、 finishtime=0;/完成时间 int wasttime=0;/周转时间 int weighttime=0;/带权周转时间 struct process *p=first-next; struct process *r; cout/*/endl; coutFCFS调度算法基本信息nendl; cout进程名 到达时间 服务时间 开始执行时间 完成时间周转时间 带权周转时间servtime + startime; wasttime= finishtime-p-attime; weighttime = wasttime / p-servtime; coutnumsetw(8)attimes

8、etw(10)servtimesetw(10)startimesetw(14)finishtimesetw(8)wasttimetweighttimenext; startime +=r-servtime; #endif动态优先权调度算法 privilege.h#ifndef PRIVILEGE_H#define PRIVILEGE_Hstruct process1 int pcb; /进程号PCB int privilege,cpu; /进程优先权,所需CPU时间 process1 *next; ;/*优先权调度算法所需函数声明*/struct process1*creatlist1();

9、/新建链表(就绪队列)void insert1(struct process1 *first,struct process1 *s); /增加一个进程或将一个进程查入到队列中void del1(struct process1 *first,struct process1 *s); /删除(撤销)一个进程void print1(struct process1 *first); /打印函数struct process1* search(struct process1 *head,struct process1 *s); /*优先权调度算法所需函数*/struct process1*creatlis

10、t1(int n) srand(int)time(0); struct process1 *first =new process1; first -next=NULL; for (int i=0;ipcb =i; s- privilege=random(20)+5; s-cpu=random(20)+1; insert1(first,s ); return first;void insert1(struct process1 *first,struct process1 *s) /插入节点 struct process1 *p=search(first,s); s-next=p-next; p

11、-next=s; /return;struct process1* search(struct process1 *first,struct process1 *s) /查找第一个到达时间大于等于AT的节点,返回其前一个指针 struct process1 *p,*q; p=first; q=first-next; while(q!=NULL&q-privilege=s-privilege) p=q; q=q-next; return p;void del1(struct process1 *first,struct process1 *s) struct process1 *p,*r; p=

12、first-next; r=first; int a=1; while (a) if (p=s) r-next=p-next; /free(p) ; a=0; else r=p; p=p-next; void print1(struct process1 *first) /打印函数 struct process1 *p; p =first-next; cout进程号 进程优先权 进程所需CPU片数endl; while (p) coutpcbsetw(8)privilegesetw(12)cpunext; void privilege(struct process1 *first) struc

13、t process1* p,*r=first,*t; p=first-next; int b=0; while (first-next) r=first; p=first-next; cout/*b*/endl; cout *进程运行前*cpu =p-cpu-1; p-privilege =p-privilege-3; if (p-privilegeprivilege =0; cout *进程运行后*endl; print1(r); cout/*/ncpu = 0) del1(r,p); else t=p; del1(r,p); insert1(r,p); b+; #endif时间片轮转调度算

14、法 round.h#ifndef ROUND_H#define ROUND_Hstruct process2 int pcb; /进程号PCB int roundpiece; /轮转时间片数 int needpiece; /进程所需时间片数 int cpupiece; /占用CPU时间片数 process2 *next; ;struct process2*creatlist2(int); /新建一个链表void print2(struct process2 *first); /打印函数void insert2(struct process2 *first,struct process2 *s)

15、; /插入节点void del2(struct process2 *first,struct process2 *s); /删除一个进程struct process2*creatlist2(int n) srand(int)time(0); struct process2*first=new process2; first-next=NULL; for (int i=0;ipcb=i; s-roundpiece=random(2)+1; s-needpiece=random(20); s-cpupiece=0; insert2(first,s); return first;void inser

16、t2(struct process2 *first,struct process2 *s) struct process2 *r=first; struct process2 *p; while(r)p=r;r=r-next; p-next=s;p=s; p-next=NULL;void del2(struct process2 *first,struct process2 *s) struct process2 *p,*r; p=first-next; r=first; int a=1; while (a) if (p=s) r-next=p-next; /free(p) ; a=0; el

17、se r=p; p=p-next; void print2(struct process2 *first) /打印函数 struct process2 *p; p =first-next; /cout随机产生的进程的信息如下endl; cout进程名 轮转时间片数 所需时间片数 占用时间片数endl; while (p) coutpcbsetw(8)roundpiecesetw(14)needpiecesetw(14)cpupiecesetw(5)next; void round(struct process2 *first) struct process2* p,*r=first; p=fi

18、rst-next; int b=0; while (first-next) /r=first; p=first-next; cout/*b*/endl; cout -进程运行前-needpiece =p-needpiece-1; p-cpupiece =p-cpupiece+1; cout -进程运行后-endl; print2(r); cout/*/nneedpiece cpupiece=p-roundpiece) p-cpupiece=0; del2(r,p); insert2(r,p); b+; #endif六 实验结果输入随机产生的进程数目 4输入选择调度算法 1输入选择调度算法 2输入选择调度算法 3七 实验总结 通过次实验模拟在单处理机情况下的处理机调度问题,加深了对进程调度的理解。 在次试验中,由于各个调度算法用到的数据结构不同,所以采用了不同的结构体来存放各个调度算法所用的信息。 在动态优先权调度算法中,当前进程用完时间片后,其优先权减去一个常数3,有可能出现优先权低于0的情况,在此情况下没有采取其它措施,后来经老师提醒改为低于0时 ,就将其优先权置为0,这样就好了。

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2