进程调度模拟程序设计.doc_第1页
进程调度模拟程序设计.doc_第2页
进程调度模拟程序设计.doc_第3页
进程调度模拟程序设计.doc_第4页
进程调度模拟程序设计.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

进程调度模拟程序设计编写一个进程调度程序,允许多个进程共享进程调度程序。 进程调度算法:采用最高优先数优先的调度算法(即把处理机分配给优先数最高的进程)和先来先服务算法。 每个进程有一个进程控制块( PCB)表示。进程控制块可以包含如下信息:进程名、优先数、到达时间、需要运行时间、已用CPU时间、进程状态等等。 进程的优先数及需要的运行时间可以事先人为地指定(也可以由随机数产生)。进程的到达时间为输入进程的时间。 进程的运行时间以时间片为单位进行计算。 每个进程的状态可以是就绪 W(Wait)、运行R(Run)、或完成F(Finish)三种状态之一。 就绪进程获得 CPU后都只能运行一个时间片。用已占用CPU时间加1来表示。 如果运行一个时间片后,进程的已占用 CPU时间已达到所需要的运行时间,则撤消该进程,如果运行一个时间片后进程的已占用CPU时间还未达所需要的运行时间,也就是进程还需要继续运行,此时应将进程的优先数减1(即降低一级),然后把它插入就绪队列等待CPU。 每进行一次调度程序都打印一次运行进程、就绪队列、以及各个进程的 PCB,以便进行检查。 重复以上过程,直到所要进程都完成为止模拟进程调度算法用C+的代码描述: #include iostream.h /define pcb typedef struct pcb char name10; /进程名 char state; /状态w(就绪)r(运行)f(结束) int id; /id号 int super; /优先级 int ntime; /需运行的时间 int rtime; /已运行的时间 struct pcb *next; *pcb1; pcb1 s,w;/define two publiced linknode ,one is s(ready queue),one is w(blocked queue) /initialize two queues void init(pcb1 &r) r=NULL;/both queues is the kind of head index /print the information of the ready queue void print() pcb1 p; cout您现在查看的是就绪队列的信息: ; cout进程号 进程名 优先级 状态已运行时间 需运行时间next) coutid name super state rtime ntimeendl; /print the information of the blocked queue void print1() pcb1 p; cout您现在查看的是阻塞队列的信息; cout进程号 进程名 优先级 状态 已运行时间 需运行时间next) coutid name super state rtime ntimertime=p-ntime) p-state=F;/if one process finshed then change tis state cout进程id 已经结束super=r-super)/the super of the process which wait insert to the queue is highter than the super of the first process of the queue p-next=r; r=p; else p1=r; p2=r-next; if(p2=NULL)/only one process in the queue r-next=p; else while(in=0&p2!=NULL)/insert to the middle of the queue if(p-super=p2-super) p-next=p2; p1-next=p; in=1; else p1=p1-next; p2=p2-next; if(in=0)/link to the last of ready queue p1-next=p; /block one process and insert to block queue void block() if(empty(s) if(s-next=NULL) sort(w,s); s=s-next; else pcb1 p1; p1=s; s=s-next; p1-next=NULL; sort(w,p1); else cout现在就绪队列已经为空,再没有进程需要阻塞next; p1-next=NULL; sort(s,p1); else cout阻塞队列已经为空,没有进程再需要唤醒next; p-rtime+; p-super-; p-next=NULL; sort(s,p); else /yes s=s-next; else cout就绪队列已经为空endl; /creat process void input() pcb1 p2; p2=new pcb; coutp2-idp2-namep2-superp2-ntime; p2-rtime=0; p2-state=W; p2-rtime=0; p2-next=NULL; sort(s,p2); /main function void main() char ch; init(s); init(w); cout*进程调度模拟程序开始*endl; cout-w/唤醒进程-r/运行进程-z/阻塞进程-q/退出程序-endl; cout-c/创建进程-s /查看就绪进程-l/查看阻塞队列-endl; while(ch!=q) cout请输入一个字符ch; switch(ch) case c:input()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论