操作系统课程设计报告(编辑修改稿)内容摘要:

*/ ProcessCreate()。 /*创建就绪进程队列 */ MultiDispatch()。 /*算法开始 */ Output()。 /*输出最终的调度序列 */ return 0。 } void Output() /*进程信息输出函数 */ { ReadyQueue *print = Head。 PCB *p。 printf(进程名 \t优先级 \t轮数 \tcpu时间 \t需要时间 \t进程状态 \t计数器 \n)。 while(print) { if(print LinkPCB != NULL) { p=print LinkPCB。 while(p) { printf(%s\t%d\t%d\t%d\t%d\t\t%c\t\t%d\n,pname,pprio,pround,pcputime,pneedtime,pstate,pcount)。 p = pnext。 } } print = printnext。 } p = finish。 while(p!=NULL) { printf(%s\t%d\t%d\t%d\t%d\t\t%c\t\t%d\n,pname,pprio,pround,pcputime,pneedtime,pstate,pcount)。 p = pnext。 } p = run。 while(p!=NULL) { printf(%s\t%d\t%d\t%d\t%d\t\t%c\t\t%d\n,pname,pprio,pround,pcputime,pneedtime,pstate,pcount)。 p = pnext。 } } void InsertFinish(PCB *in) /*将进程插入到完成队列尾部 */ { PCB *fst。 fst = finish。 if(finish == NULL) { innext = finish。 finish = in。 } else { while(fstnext != NULL) { fst = fstnext。 } in next = fst next。 fst next = in。 } } void InsertPrio(ReadyQueue *in) /*创建就绪队列,规定优先数越小,优先级越低 */ { ReadyQueue *fst,*nxt。 fst = nxt = Head。 if(Head == NULL) /*如果没有队列,则为第一个元素 */ { innext = Head。 Head = in。 } else /*查到合适的位置进行插入 */ { if(in prio = fst prio) /*比第一个还要大,则插入到队头 */ { innext = Head。 Head = in。 } else { while(fstnext != NULL) /*移动指针查找第一个别它小的元素的位置进行插入 */ { nxt = fst。 fst = fstnext。 } if(fst next == NULL) /*已 经搜索到队尾,则其优先级数最小,将其插入到队尾即可 */ { in next = fst next。 fst next = in。 } else /*插入到队列中 */ { nxt = in。 in next = fst。 } } } } void PrioCreate() /*创建就绪队列输入函数 */ { ReadyQueue *tmp。 int i。 printf(输入就绪队列的个数: \n)。 scanf(%d,amp。 ReadyNum)。 printf(输入每个就绪队列的 CPU时间片: \n)。 for(i = 0。 i ReadyNum。 i++) { if((tmp = (ReadyQueue *)malloc(sizeof(ReadyQueue)))==NULL) { perror(malloc)。 exit(1)。 } scanf(%d,amp。 (tmpround))。 /*输入此就绪队列中给每个进程所分配的 CPU时间片 */ tmp prio = 50 tmpround。 /*设置其优先级,时间片越高,其优先级越低 */ tmp LinkPCB = NULL。 /*初始化其连接的进程队列为空 */ tmp next = NULL。 InsertPrio(tmp)。 /*按照优先级从高到低,建立多个就绪队列 */ } } void GetFirst(ReadyQueue *queue) /*取得某一个就绪队列中的队头进程 */ { run = queue LinkPCB。 if(queue LinkPCB != NULL) { run state = 39。 R39。 queue LinkPCB = queue LinkPCB next。 run next = NULL。 } } void InsertLast(PCB *in,ReadyQueue *queue) /*将进程插入到就绪队列尾部 */ { PCB *fst。 fst = queueLinkPCB。 if( queueLinkPCB == NULL) { innext = queueLinkPCB。 queueLinkPCB = in。 } else { while(fstnext != NULL) { fst = fstnext。 } in next = fst next。 fst next = in。 } } void ProcessCreate() /*进程创建函数 */ { PCB *tmp。 int i。 printf(输入进程的个数: \n)。 scanf(%d,amp。 num)。 printf(输入进程名字和进程所需时间: \n)。 for(i = 0。 i num。 i++) { if((tmp = (PCB *)malloc(sizeof(PCB)))==NULL) { perror(malloc)。 exit(1)。 } scanf(%s,tmpname)。 getchar()。 /*吸收回车符号 */ scanf(%d,amp。 (tmpneedtime))。 tmp cputime = 0。 tmp state =39。 W39。 tmp prio = 50 tmpneedtime。 /*设置其优先级,需要的时间越多,优先级越低 */ tmp round = Head round。 tmp count = 0。 InsertLast(tmp,Head)。 /*按照优先级从高到低,插入到就绪队列 */ } } void RoundRun(ReadyQueue *timechip) /*时间片轮转调度算法 */ { int flag = 1。 GetFirst(timechip)。 while(run != NULL) { while(flag) { runcount++。 runcputime++。 runneedtime。 if(runneedtime == 0) /*进程执行完毕 */ {。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。