欢迎来到天天文库
浏览记录
ID:41657067
大小:90.20 KB
页数:5页
时间:2019-08-29
《实验三进程调度45》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、信息工程学院实验报告适用于计算机课程成绩:指导教师(签名):课程名称:操作系统实验项目名称:进程调度实验时间:2014.4.18班级:姓名:学号:实验目的:用高级语言编写和调试-个有N个进程并行的进程调度程序,以加深对进程的概念及进程调度算法的理解。实验环境:VC++6.0实验内容及过程:1•编写一个有N个进程并行的进程调度程序。2.在上机环境中输入程序,调试,编译。3.设计输入数据,写出程序的执行结果。#include"stdio.h"#includc#include#definegetpch(type)(type*)
2、malloc(sizeof(type))#defineNULL0structpcb{/*定义进程控制块PCB*/charname[10];charstate;intsuper;intmime;intrtime;structpcb*link;}*ready=NULL/p;typedefstructpcbPCB;sorl()/*建立对进程进行优先级排列函数*/{PCB水first,^second;intinsert=0;if((ready==NULL)11((p->s叩er)>(ready->super)))/*优先级授大者,插入队首引p->Iink=ready
3、;rcady=p;)else/*进程比较优先级,插入适当的位置中*/{first=ready;sccond=first->link;while(second!=NULL){if((p->super)>(second->super))/*若插入进程比当前进程优先数大,*/{严插入到当前进程前面勺p->link=second;first->link=p;second=NULL;insert=l;)else/*插入进程优先数最低,则插入到队尾*/{first=first->link;second=second・>link;))if(inscrt—0)first->
4、link=p;}Iinput()/*建立进程控制块函数*/{inti,num;printfC'请输入进程数目:“);scanf("%d",&num);for(i=0;iname);printf("输入进程优先数:”);scanf("%d",&p->super);printf(''输入进程运行时间:”);scanf(H%d",&p->niime);printf("");p->rti
5、mc=O;p->statc='w';p->link=NULL;sort();/*调用sort函数*/))intspace(){int1=0;PCB*pr=ready;while(pr!=NULL){1卄;pr=pr->link;)return(I);)disp(PCB*pr)/*建立进程显示函数,用于显示当前进程*/{prinlf("iiqnametstatetsupertndtimetruntimeprintf("l%st",pr->name);printf("l%ct",pr->statc);printf("l%dt",pr->super
6、);printf("l%dt",pr->ntime);prinlf("l%dt",pr->rlime);printf(””);)check()/*建立进程查看函数*/{PCB*pr;printf("****当前正在运行的进程M:%s",p->name);/*显示当前运行进程旬disp(p);pr=ready;printf("**和当前就绪队列状态为:”);/*显示就绪队列状态*/whilc(pr!=NULL){disp(pr);pr=pr->link;))destroyO/*建立进程撤消函数(进程运行结束,撤消进程尸/{printf("
7、n进程
8、%s]已完成.",p->name);free(p);}runningO/*建立进程就绪函数(进程运行时间到,置就绪状态*/{(p->rtime)++;if(p->rtime==p・>ntimc)destroyO;/*调用destroy函数*/else{(p->super)—;p->state=w';sort();/*调用sort函数*/))main()/*主函数*/{intlcn,h=0;charch;input();len=space();while((len!=0)&&(ready!=NULL)){ch=getchar();h++;print
9、f(HTheexecutenumber:%d
此文档下载收益归作者所有