时间片算法 编译原理.doc_第1页
时间片算法 编译原理.doc_第2页
时间片算法 编译原理.doc_第3页
时间片算法 编译原理.doc_第4页
时间片算法 编译原理.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

/夏国峰 E01014130 时间片算法#include #include #define getpch(type) (type*)malloc(sizeof(type)struct pcbchar name10; char state; int ntime; int rtime; struct pcb* link; *ready=NULL, *p;/结构体typedef struct pcb PCB;int start; void sort() PCB *end, *recent;int inlist=0; if(ready=NULL)ready=p; else recent=ready;end=recent-link; while(end!=NULL) recent=recent-link; end=end-link;if(end=NULL) recent-link=p; void input() /进程输入函数int i,num;printf(nPlease input the number of processes:);scanf(%d,&num); /定义进程个数 numfor(i=0;iname);printf(nInput the running time of the process:);scanf(%d,&p-ntime);printf(n); p-rtime=0; p-state=w; /进程就绪状态 p-link=NULL; sort(); int space() /统计链表中的进程数int l=0;PCB *pr=ready;while(pr!=NULL)l+; /用于记录链表中的进程数pr=pr-link;return(l);void disp(PCB *pr) /打印显示当前正在执行的进程的相关信息printf(nqnametstatetndtimetruntimen);printf(|%st,pr-name);printf(|%ct,pr-state);printf(|%dt,pr-ntime);printf(|%dt,pr-rtime);printf(n);void check()PCB *pr;printf(n *The current running process is: %sn,p-name);disp(p);pr=ready; /记住表头进程printf(n *The state of the Waiting List:n);while(pr!=NULL) /打印出剩余的所有进程的相关信息disp(pr);pr=pr-link;if(pr=NULL)printf(nNo waiting process!n);void destroy() /打印进程执行信息提示printf(nProcess %s has finished.n,p-name);free(p); /释放临时变量p的内存空间 void running()(p-rtime)+; if(p-rtime=p-ntime)destroy();elsep-state=w;sort(); /重新插入链表void Menu() char menu;printf( * 菜单选择 *n);printf( * 1: ENTER SIMULATE *n);printf( * 2: QUIT PROCESS *n); printf(Please input your choice!n); scanf(%c,&menu);switch(menu) /菜单选项case 1:start=1;system(cls);printf(n* MODE OF SIMILATE! *n*时间片进程调度*n);break; case 2:exit(0); break;default:exit(0);break;void main()int len, h=0;char ch;Menu();if(start=1)input();len=space();while(len!=0)&(ready!=NULL) ch=getchar();h+;printf(n The execute number: %d n,h);p=ready;ready=p-link;p-link=NULL;p-state=R;check();running();printf(nProcess A

温馨提示

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

评论

0/150

提交评论