预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

课程计算机操作系统原理实验名称进程调度模拟算法 院系计算机科学与技术专业班级计0804姓名李超学号200807010409 实验日期2011年05月11日实验报告日期2011年05月11日 1.内容:设计一个简单的进程调度算法,模拟OS中的进程调度过程; 2.要求: ①进程数不少于5个; ②进程调度算法任选; 可以用动态优先数加时间片轮转法实现进程调度,每运行一个时间片优先数减3; ③用C语言编程; ④程序运行时显示进程调度过程。 3.步骤: ①设计PCB及其数据结构: 进程标识数:ID 进程优先数:PRIORITY(优先数越大,优先级越高) 进程已占用时间片:CPUTIME,每得到一次调度,值加1; 进程还需占用时间片:ALLTIME,每得到一次调度,该值减1,一旦运行完毕,ALLTIME为0) 进程队列指针:NEXT,用来将PCB排成队列 进程状态:STATE(一般为就绪,可以不用) ②设计进程就绪队列及数据结构; ③设计进程调度算法,并画出程序流程图; ④设计输入数据和输出格式; 结构格式:当前正运行的进程:0 当前就绪队列:2,1,3,4 ⑤编程上机,验证结果。 4.提示: 假设调度前,系统中有5个进程,其初始状态如下: ID01234PRIORITY93830290可否考虑用数组或链表去实现CPUTIME00000ALLTIME32634STATEreadyreadyreadyreadyready①以时间片为单位调度运行; ②每次调度ALLTIME不为0,且PRIORITY最大的进程运行一个时间片; ③上述进程运行后其优先数减3,再修改其CPUTIME和ALLTIME,重复②,③ ④直到所有进程的ALLTIME均变为0。 5.书写实验报告 ①实验题目; ②程序中所用数据结构及说明; ③清单程序及描述; ④执行结果。 #include"stdio.h" #include<stdlib.h> #include<conio.h> #definegetpch(type)(type*)malloc(sizeof(type)) #defineNULL0 structpcb//定义进程控制块PCB { charname[10]; charstate; intsuper; intruntime; intwaittime; structpcb*link; }*ready,*p; //*ready=NULL,*p; //typedefstructpcbPCB; voidsort()//建立对进程进行优先级排列函数 { //PCB*first,*second; pcb*first,*second; intinsert=0; if((ready==NULL)||((p->super)>(ready->super)))//优先级最大者,插入队首 { p->link=ready; ready=p; } else//进程比较优先级,插入适当的位置中 { first=ready; second=first->link; while(second!=NULL) { if((p->super)>(second->super))//若插入进程比当前进程优先数大 { p->link=second; first->link=p; second=NULL; insert=1;//插入到当前进程前面 } else { first=first->link; second=second->link; } } if(insert==0) first->link=p; } return; } voidsortruntime()//运行时间处理函数 { //PCB*first,*second; pcb*first,*second; intinsert=0; if((ready==NULL)||((p->runtime)<(ready->runtime)))//处理时间少的插入前边 { p->link=ready; ready=p; } else//进程处理时间比较插入合适的位置,插入适当的位置中 { first=ready; second=first->link; while(second!=NULL) { if((p->runtime)<(second->runtime))//处理时间少的插入前边 { p->link=second; fi