进程调度算法设计报告

上传人:简****9 文档编号:109962932 上传时间:2019-10-28 格式:DOC 页数:6 大小:45KB
返回 下载 相关 举报
进程调度算法设计报告_第1页
第1页 / 共6页
进程调度算法设计报告_第2页
第2页 / 共6页
进程调度算法设计报告_第3页
第3页 / 共6页
进程调度算法设计报告_第4页
第4页 / 共6页
进程调度算法设计报告_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《进程调度算法设计报告》由会员分享,可在线阅读,更多相关《进程调度算法设计报告(6页珍藏版)》请在金锄头文库上搜索。

1、实验一 进程调度一、目的要求用高级语言编写和调试一个进程。以加深对进程的概念及进程调度算法的理解。二、程序的过程设计进程调度算法:采用最高优先数优先的调度算法,即把处理机分配给优先数最高的进程。每个进程由一个进程控制块(PCB)表示。进程控制块可以包含如下信息:进程名、优先数、需要运行的时间、已占用的CPU时间、进程状态等等。进程的优先数及所需要运行的时间可以事先人为地指定(也可由随机数产生)。进程的运行时间以时间片为单位进行计算。每个进程的状态可以是就绪W(Wait),运行R(Run),或完成F(Finish)三种状态之一。各个就绪进程依优先数从高到低排列。总是把CPU分配给优先数最高的进程

2、。就绪进程获得CPU后都只能运行一个时间片。用已占用CPU时间加1来表示。如果运行一个时间片后,进程的已占用CPU时间已达到所需要的运行时间,则撤销该进程。如果运行一个时间片后进程的已占用CPU时间还未达所需的运行时间,也就是进程还需要继续运行,此时应将进程的优先数减1(即降低一级),然后把它插入就绪队列等待CPU。每进行一次调度程序都打印一次运行进程,就绪队列。以及各个进程的PCB,以便进行检查。重复上述过程,直到所要进程都完成为止。三、调度算法的流程图如下:开始初始化PCB,输入进程信息各进程按优先数从高到低排列 就绪队列空? 结束就绪队列链首进程投入运行时间片到运行进程已占用CPU时间+

3、1运行进程已占用CPU时间已达到所需的运行时间?使运行进程的优先数-1 进程完成把运行进程插入就绪队列 撤销该进程四、程序代码:#include#include#include#define getpcb(type)(type*)malloc(sizeof (type)#define NULL 0#define waittime 2 struct pcb char name10; char state; int super; int ntime; int wtime; int rtime; struct pcb*link; *ready=NULL,*p,*f; typedef struct p

4、cb PCB;void sort();void destroy();void input()int i,num;/ clrscr(); printf(ninput process nunmber?); scanf(%d,&num); for(i=0;iname); printf(nthe super of process:); scanf(%d,&p-super); printf(nthe time need:); scanf(%d,&p-ntime); printf(n); p-rtime=0;p-wtime=0;p-state=w; p-link=NULL; sort(); void so

5、rt()PCB *fir,*sec;int ins=0;if(ready=NULL)|(p-super)(ready-super) p-link=ready; ready=p; elsefir=ready; sec=fir-link; while(sec!=NULL) if(p-super)(sec-super) p-link=sec; fir-link=p; sec=NULL; ins=1; elsefir=fir-link; sec=sec-link; if(ins=0)fir-link=p; void sort1(PCB *p)PCB *fir,*sec;PCB *th;int ins=

6、0;fir=ready;th=ready;sec=fir-link;if(ready!=NULL)while(th-link!=p)&(th-link!=NULL)th=th-link;if(fir-link=NULL)|(fir=p) return;else if(p-superready-super)th-link=p-link;p-link=ready;ready=p;else while(sec-link!=p)&(sec-link!=NULL) if(p-super)(sec-super) th-link=p-link; fir-link=p; p-link=sec; elsefir

7、=fir-link; sec=sec-link; void running() f=NULL; (p-rtime)+; if(p-rtime=p-ntime) destroy(); else (p-super)-; p-state=w; p-wtime=0; f=p; / sort(); if(ready!=NULL) p=ready; while(p!=NULL) p-wtime+; if(p-wtime=2) p-super+; p-wtime=0; sort1(p); p=p-link; if(f!=NULL)p=f;sort();int space() int l=0; PCB*pr=

8、ready; while(pr!=NULL) l+; pr=pr-link; return(l);void disp(PCB *pr);void check()PCB*pr; printf(n*Now the process running is:%s,p-name);disp(p);pr=ready;printf(n*Now the ready queue is:n);while(pr!=NULL)disp(pr); pr=pr-link; void disp(PCB *pr)printf(nqnametstatetsupertndtimetwtimetruntimen);printf(|%

9、st,pr-name);printf(|%ct,pr-state);printf(|%dt,pr-super);printf(|%dt,pr-ntime);printf(|%dt,pr-wtime);printf(|%dt,pr-rtime);printf(n);void destroy()printf(nprocess%s has finished.n,p-name); free(p);void main () int len=0, h=0; input(); len=space(); while(len!=0)&(ready!=NULL) getchar(); h+;coutnthe execute numberhlink; p-link=NULL; p-state=R; check(); running(); printf(npress any key to continue.); getchar(); printf(nnthe process has been finished.n); getchar();

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

当前位置:首页 > 商业/管理/HR > 管理学资料

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