使用动态优先权和时间片轮转的进程调度算法的模拟

上传人:豆浆 文档编号:882151 上传时间:2017-05-20 格式:DOC 页数:8 大小:44.50KB
返回 下载 相关 举报
使用动态优先权和时间片轮转的进程调度算法的模拟_第1页
第1页 / 共8页
使用动态优先权和时间片轮转的进程调度算法的模拟_第2页
第2页 / 共8页
使用动态优先权和时间片轮转的进程调度算法的模拟_第3页
第3页 / 共8页
使用动态优先权和时间片轮转的进程调度算法的模拟_第4页
第4页 / 共8页
使用动态优先权和时间片轮转的进程调度算法的模拟_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《使用动态优先权和时间片轮转的进程调度算法的模拟》由会员分享,可在线阅读,更多相关《使用动态优先权和时间片轮转的进程调度算法的模拟(8页珍藏版)》请在金锄头文库上搜索。

1、河南师范大学计算机与信息工程学院计算机与信息工程学院设计性实验报告专业:计算机科学与技术 年级/班级:2103 级 20152016学年第一学期课程名称 操作系统 指导教师 张倩倩学号姓名 1308114088 郅伟远实验地点 网络实验室 216 实验时间 2015/12/5项目名称 使用动态优先权和时间片轮转的进程调度算法的模拟 实验类型 设计性一、实验目的通过动态优先权调度算法的模拟加深进程概念和进程调度过程的理解。二、实验仪器或设备虚拟机三、总体设计(设计原理、设计方案及流程等)实验内容(1) 在 Linux 下用 C 语言编程模拟 N 个进程采用高优先权优先(要求采用动态优先权)和简单

2、时间片轮转两种进程调度算法。为了清楚地观察每个进程的调度过程,程序应将每个时间片内的进程情况显示出来;(2) 进程控制块是进程存在的唯一标志,因此,在模拟算法中每一个进程用一个进程控制块 PCB 来代表,PCB 用一结构体表示。包括以下字段: 进程标识数 id,或者进程的名称 name; 进程优先数 priority,并规定优先数越大的进程,其优先权越高; 进程需要运行的 CPU 时间 ntime; 进程的运行时间 rtime; 进程状态 state; 队列指针 next,用来将 PCB 排成队列。(3) 进程在运行过程中其状态将在就绪、执行、阻塞(可选) 、完成几种状态之间转换,同时进程可能

3、处于不同的队列中,如就绪队列、阻塞队列(可选) 。在两种调度算法中,考虑分别可以选择什么样的队列及如何实现进程的入队、出队操作;河南师范大学计算机与信息工程学院(4) 为了便于处理,优先权调度每次也仅让进程执行一个时间片,若在一个时间片内未运行结束,调整进程优先级将其插入就绪队列,进行新一轮调度;(5) 优先数改变原则: 进程每运行若一个时间单位,优先数减 3; 进程在就绪队列中呆一个时间片,优先数增加 1。 (仅供参考,合理即可)(6) 优先权调度中,对于遇到优先权一致的情况,可采用 FCFS策略解决;(7) 由于是模拟进程调度,所以,对被选中的进程并不实际启动运行,而是修改进程控制块的相关

4、信息来模拟进程的一次运行;(8) 为了清楚地观察诸进程的调度过程,程序应将每个时间片内的进程的情况显示出来,参照格式如下:id cputime needtime priority(count) state0 0 2 48 ready1 0 3 47 ready2 0 6 44 ready3 0 5 45 ready4 0 4 46 ready简单时间片轮转调度模拟程序见 roundrobin.c,优先权调度大家请参考时间片轮转自行实现,有自己想法的同学可以按照自己的思路独立完成实验,而不用参考 roundrobin.c 程序。四、实验步骤(包括主要步骤、代码分析等)#include stdio

5、.h #include #define getpch(type) (type*)malloc(sizeof(type) struct pcb char name10; char state; int count; int ntime; int rtime; int priority;struct pcb* link; 河南师范大学计算机与信息工程学院*ready=NULL,*tail=NULL,*p;typedef struct pcb PCB; int slice;sort() PCB *first,*second;int insert=0;if(ready=NULL)|(p-priorit

6、y)(ready-priority)p-link=ready;ready=p;elsefirst=ready;second=first-link;while(second!=NULL)if(p-priority)(second-priority)p-link=second;first-link=p;second=NULL;insert=1;elsefirst=first-link;second=second-link;if(insert=0)first-link=p; input() int i,num; printf(n please enter a number of processes:

7、);scanf(%d,&num);for(i=0;iname); printf(n please enter the process running time:); scanf(%d,&p-ntime); printf(n please enter the priority number :);scanf(%d,&p-priority);printf(n); p-rtime=0;p-state=w; p-count=0;p-link=NULL;sort(); printf(n please enter the time slice size:);scanf(%d,&slice); int sp

8、ace() int l=0; PCB* pr=ready; while(pr!=NULL) l+; pr=pr-link; return(l); disp(PCB * pr) printf(nqname tstate tcount tntime trtime tpriority n); printf(%st,pr-name); printf(%ct,pr-state); printf(%dt,pr-count); printf(%dt,pr-ntime); printf(%dt,pr-rtime); printf(%dt,pr-priority);printf(n); check() PCB*

9、 pr; printf(n * the current running process is :%s,p-name); disp(p); 河南师范大学计算机与信息工程学院pr=ready; printf(n * the current ready queue state :n); while(pr!=NULL) disp(pr); pr=pr-link; destroy() printf(n process %s finish .n,p-name); free(p); running() int tempt;tempt = p-ntime - p-rtime;if(temptslice)p-r

10、time+=slice; elsep-rtime+=tempt;p-count+;check();if(p-rtime=p-ntime) destroy(); else p-priority-=3;p-state=w;sort(); main() int len,h=0; char ch; input(); len=space(); while(len!=0)&(ready!=NULL) h+;printf(n The execute number:%d n,h);p=ready; ready=p-link; 河南师范大学计算机与信息工程学院p-link=NULL; p-state=R; ru

11、nning(); printf(nn all processes have been completed.n); rootlocalhost # gcc cmc.c -o cmcrootlocalhost # ./cmcplease enter a number of processes:3process number No.0:please enter the process name :3please enter the process running time:2please enter the priority number :5process number No.1:please e

12、nter the process name :45please enter the process running time:8please enter the priority number :4process number No.2:please enter the process name :6please enter the process running time:4please enter the priority number :1please enter the time slice size:5The execute number:1河南师范大学计算机与信息工程学院* the

13、 current running process is :3qname state count ntime rtime priority3 R 1 2 2 5* the current ready queue state :qname state count ntime rtime priority45 w 0 8 0 4qname state count ntime rtime priority6 w 0 4 0 1process 3 finish .The execute number:2* the current running process is :45qname state cou

14、nt ntime rtime priority45 R 1 8 5 4* the current ready queue state :qname state count ntime rtime priority6 w 0 4 0 1The execute number:3* the current running process is :6qname state count ntime rtime priority6 R 1 4 4 1* the current ready queue state :qname state count ntime rtime priority45 w 1 8 5 1process 6 finish .The execute number:4* the

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号