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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

实验五模拟进度调度.docx

1、实验五模拟进度调度实验五 模拟进度调度班级:09网络工程 姓名:林泽全 学号:0914021161、 实验目的1. 理解PCB2. 理解进程的并发执行3. 理解进程的FCFS、动态优先权和时间片轮转三种调度算法,并模拟实现这三种算法2、 实验器材 微型计算机、fedora版本的Linux系统3、 实验内容PCB在本设计中的基本结构Typedef struct nodeChar name10;/*进程标识符*/Float prin;/*进程的优先级*/Int round;/*进程轮转的时间片*/Int needtime;/*进程还需要的cpu时间*/Int waittime;/*进程进入系统后等

2、待cpu的时间*/Char state;/*进程的状态*/Struct node *next;/*链接指针*/PCB设计三个队列:就绪、完成、运行,其中运行队列中应该只有一个进程。创建进程,就是用户输入进程的标识符和运行所需时间,系统为其生成一个PCB,存放进程的信息,将新生成的PCB插入就绪队列。进程任务结束,系统将其PCB插入完成队列,该进程就消亡。任务1:动态优先权调度算法模拟:优先权= 1 + 等待时间/需要服务时间-最高响应比优先(1) 输入一批作业的进程标识和估计运行时间,将其PCB插入就绪队列(2) 当就绪队列非空、CPU空闲时,计算出每个就绪进程的优先权(3) 将优先权最高的进

3、程从就绪队列移入运行队列,状态改为运行(模拟进程调度)(4) 在屏幕上输出当前所有进程的状态和优先权信息(已完成进程不显示)(5) 让运行进程执行足够的服务时间(6) 将运行进程移入完成队列(7) 提示可以输入新的作业,如果有新作业输入,则转向(1) ,否则转向(2)(8) 如果就绪队列为空,则结束程序框图如下:程序源代码如下:#include #include typedef struct node char name10; /进程标识符 float prin; /进程的优先级 int round; /进程轮转的时间片 int needtime; /进程还需要当CPU时间 int waitt

4、ime; /进程进入系统后等待当CPU的时间 char state; /进程当状态 struct node *next; /链接指针 PCB;PCB *readyQueue=NULL, *runningQueue=NULL, *finishedQueue=NULL, *finishedQueueTail=NULL, *readyQueueTail=NULL, pcbPool10;int poolSize = 0;void createPro(); /根据进程标识和估计运行时间,将其PCB插入就绪队列void readyQueueNotNull(); /当就绪队列非空、CPU空闲时,计算每个就绪

5、进程当优先权void insertRunningQueue(); /将优先权最高当进程从就绪队列移入运行队列,状态改为运行void displayQueue(); /将所有非结束进程的状态和优先权信息显示在屏幕void runPro(); /让运行进程执行足够的服务时间void addNewPro(); /提示可以输入新的进程int main(int argc, char const *argv) createPro(); while(readyQueue!=NULL) readyQueueNotNull(); insertRunningQueue(); displayQueue(); run

6、Pro(); puts(); addNewPro(); puts(Bye); return 0;void createPro() char name10; char stop = y; int needtime, i=0; while(stop=y) /获取用户输入进程名 puts(Please input the process name: ); scanf(%s, name); strcpy(pcbPooli.name, name); /获取用户输入进程需要时间 puts(Please input the need of time: ); scanf(%d, &needtime); pcb

7、Pooli.needtime = needtime; pcbPooli.state = 0; pcbPooli.next = NULL; pcbPooli.prin = 0.0f; pcbPooli.waittime = 0; if(i=0) readyQueue = &pcbPool0; readyQueueTail = &pcbPool0; else readyQueueTail-next = &pcbPooli; readyQueueTail = &pcbPooli; if(i+ 9) break; puts(Do you want to input more process(y or

8、n): ); scanf(%s, &stop); poolSize = i + 1;void readyQueueNotNull() PCB *pcb = readyQueue; while(1) pcb-prin = 1 + pcb-waittime / pcb-needtime; if(pcb-next=NULL) break; else pcb = pcb-next; void insertRunningQueue()PCB *currentPCB = readyQueue, *lastPCB = readyQueue, *lastOfChosePCB = readyQueue, *ch

9、osePCB = readyQueue; while(1) /选择优先级最高的进程 if(currentPCB-prin prin) lastOfChosePCB = lastPCB; chosePCB = currentPCB; /判断就绪队列是否判断结束 if(currentPCB-next!=NULL) lastPCB = currentPCB; currentPCB = currentPCB-next; else break; chosePCB-state = 1; /将优先级最高的进程状态标识为运行时 runningQueue = chosePCB; /将优先级最高的进程从就绪队列移

10、入运行队列 /将优先级最高的进程从就绪队列中移出 if(readyQueue=chosePCB) readyQueue = readyQueue-next; else lastOfChosePCB-next = chosePCB-next;void displayQueue() if(readyQueue!=NULL) PCB pcb = *readyQueue; while(1) printf(Process: %s State: %d prin: %fn, pcb.name, pcb.state, pcb.prin); if(pcb.next=NULL) break; else pcb =

11、 *(pcb.next); if(runningQueue!=NULL) printf(Process: %s State: %d prin: %fn, runningQueue-name, runningQueue-state, runningQueue-prin);void runPro() sleep(runningQueue-needtime); if(readyQueue!=NULL) PCB *pcb = readyQueue; while(1) pcb-waittime = pcb-waittime + runningQueue-needtime; if(pcb-next=NUL

12、L) break; else pcb = pcb-next; /将运行了需要时间的进程移入完成队列 if(finishedQueue=NULL) finishedQueue = runningQueue; finishedQueueTail = runningQueue; finishedQueueTail-next = NULL; else finishedQueueTail-next = runningQueue; finishedQueueTail = runningQueue; /清理运行时队列 runningQueue-state = 0; runningQueue = NULL;v

13、oid addNewPro() char name10; char stop = y; int needtime, i=poolSize-1; puts(Do you want to input more process(y or n): ); scanf(%s, &stop); while(stop=y) /获取用户输入进程名 puts(Please input the process name: ); scanf(%s, name); strcpy(pcbPooli.name, name); /获取用户输入进程需要时间 puts(Please input the need of time:

14、 ); scanf(%d, &needtime); pcbPooli.needtime = needtime; pcbPooli.state = 0; pcbPooli.next = NULL; pcbPooli.prin = 0.0f; pcbPooli.waittime = 0; if(readyQueue=NULL) readyQueue = &pcbPooli; readyQueueTail = &pcbPooli; else readyQueueTail-next = &pcbPooli; readyQueueTail = &pcbPooli; if(i+ 9) break; els

15、e puts(Do you want to input more process(y or n): ); scanf(%s, &stop); poolSize = i + 1; 程序运行截图如下:任务2:时间片轮转调度算法模拟输入一批作业的进程标识和估计运行时间,由其PCB组成就绪队列。时间片轮转调度,系统给就绪队列的第一个进程分配一个时间片,大小等于n (个时钟周期),再将它移入运行队列。注意,时间片的大小要比大多数进程的估计运行时间短。当时间片结束的时候,要将没有运行完的进程从运行队列移到就绪队列的末尾,再次进行调度。在每次调度时将所有进程的当前情况显示出来。程序框图如下:程序源代码如下:

16、#include #include typedef struct node char name10; /进程标识符 float prin; /进程的优先级 int round; /进程轮转的时间片 int needtime; /进程还需要当CPU时间 int waittime; /进程进入系统后等待当CPU的时间 char state; /进程当状态 struct node *next; /链接指针 PCB;PCB *readyQueue=NULL, *runningQueue=NULL, *finishedQueue=NULL, *finishedQueueTail=NULL, *ready

17、QueueTail=NULL, pcbPool10;int poolSize = 0;void createPro(); /根据进程标识和估计运行时间,将其PCB插入就绪队列void insertRunningQueue(); /将优先权最高当进程从就绪队列移入运行队列,状态改为运行void displayQueue(); /将所有非结束进程的状态和优先权信息显示在屏幕void runPro(); /让运行进程执行足够的服务时间int main(int argc, char const *argv) createPro(); while(readyQueue!=NULL) insertRunn

18、ingQueue(); displayQueue(); runPro(); puts(); puts(Bye); return 0;void createPro() char name10; char stop = y; int needtime, i=0; while(stop=y) /获取用户输入进程名 puts(Please input the process name: ); scanf(%s, name); strcpy(pcbPooli.name, name); /获取用户输入进程需要时间 puts(Please input the need of time: ); scanf(%

19、d, &needtime); pcbPooli.needtime = needtime; pcbPooli.state = 0; pcbPooli.next = NULL; pcbPooli.prin = 0.0f; pcbPooli.round = 1; if(i=0) readyQueue = &pcbPool0; readyQueueTail = &pcbPool0; else readyQueueTail-next = &pcbPooli; readyQueueTail = &pcbPooli; if(i+ 9) break; puts(Do you want to input mor

20、e process(y or n): ); scanf(%s, &stop); poolSize = i + 1;void insertRunningQueue() runningQueue = readyQueue; readyQueue = readyQueue-next; runningQueue-state = 1;void displayQueue() if(readyQueue!=NULL) PCB pcb = *readyQueue; while(1) printf(Process: %s State: %d Needtime: %dn, pcb.name, pcb.state,

21、 pcb.needtime); if(pcb.next=NULL) break; else pcb = *(pcb.next); if(runningQueue!=NULL) printf(Process: %s State: %d Needtime: %dn, runningQueue-name, runningQueue-state, runningQueue-needtime);void runPro() sleep(runningQueue-round); /模拟执行进程 /更新运行队列 runningQueue-needtime = runningQueue-needtime - r

22、unningQueue-round; runningQueue-state = 0; /将运行结束当进程移入完成队列 if(runningQueue-needtimenext = NULL; else finishedQueueTail-next = runningQueue; finishedQueueTail = runningQueue; else if(readyQueue=NULL) readyQueue = runningQueue; readyQueueTail = runningQueue; else readyQueueTail-next = runningQueue; re

23、adyQueueTail = runningQueue; readyQueueTail-next = NULL; /清理运行时队列 runningQueue = NULL;程序运行截图如下:任务2:FCFS调度算法模拟按一定的顺序输入一批作业的进程标识和估计运行时间,由其PCB按照进程标识输入的顺序组成就绪队列。当就绪队列非空、CPU空闲时,将就绪队列的第一个进程从就绪队列移入运行队列,状态改为运行。以后个步骤类似于2。程序框图如下:程序源代码如下:#include #include typedef struct node char name10; /进程标识符 float prin; /进程

24、的优先级 int round; /进程轮转的时间片 int needtime; /进程还需要当CPU时间 int waittime; /进程进入系统后等待当CPU的时间 char state; /进程当状态 struct node *next; /链接指针 PCB;PCB *readyQueue=NULL, *runningQueue=NULL, *finishedQueue=NULL, *finishedQueueTail=NULL, *readyQueueTail=NULL, pcbPool10;int poolSize = 0;void createPro(); /根据进程标识和估计运行

25、时间,将其PCB插入就绪队列void insertRunningQueue(); /将优先权最高当进程从就绪队列移入运行队列,状态改为运行void displayQueue(); /将所有非结束进程的状态和优先权信息显示在屏幕void runPro(); /让运行进程执行足够的服务时间void addNewPro(); /提示可以输入新的进程int main(int argc, char const *argv) createPro(); while(readyQueue!=NULL) insertRunningQueue(); displayQueue(); runPro(); puts()

26、; addNewPro(); puts(Bye); return 0;void createPro() char name10; char stop = y; int needtime, i=0; while(stop=y) /获取用户输入进程名 puts(Please input the process name: ); scanf(%s, name); strcpy(pcbPooli.name, name); /获取用户输入进程需要时间 puts(Please input the need of time: ); scanf(%d, &needtime); pcbPooli.needtim

27、e = needtime; pcbPooli.state = 0; pcbPooli.next = NULL; pcbPooli.prin = 0.0f; pcbPooli.waittime = 0; if(i=0) readyQueue = &pcbPool0; readyQueueTail = &pcbPool0; else readyQueueTail-next = &pcbPooli; readyQueueTail = &pcbPooli; if(i+ 9) break; puts(Do you want to input more process(y or n): ); scanf(%s, &stop);

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

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