实验项目三 进程调度
一、 实验目的
1. 理解进程控制块和进程组织方式; 2. 掌握时间片轮转调度算法实现处理机调度。
二、 实验内容
1. 建立合理的PCB数据结构,建立含有8个进程结点的就绪队列,每个进程的要求运行时间随机产生,要求每个进程的要求运行时间不大于15。
2. 设置时间片大小(3~6),使用时间片轮转调度算法实现处理机调度。
三、 源程序及运行结果
源程序:
#include
#define LEN sizeof(PCB)
struct PCB {
int name; int runtime;
int runedtime; int killtime; struct PCB *next; };
typedef struct PCB PCB;
void main(){ int timeslice = 5;
PCB *runqueue;//运行队列指针
PCB *top,*tail,*temp;//就绪队列指针 int i;
srand((int)time(0)); for(i=0;i temp=(PCB*)malloc(LEN); temp->name=i; temp->runtime=rand(); temp->runedtime=0; temp->next=NULL; temp->killtime=0; if(i==0) { top=temp; tail=temp; } else { tail->next=temp; tail=temp; } printf(\name %d, runtime=%d, runedtime=%d,killtime=%d\\n\tail->name,tail->runtime,tail->runedtime,tail->killtime); } printf(\ while(top != NULL){ runqueue = top; top = top->next; runqueue->next=NULL; runqueue->runtime =runqueue->runtime-timeslice; if(runqueue->runtime<=0) { runqueue->killtime=runqueue->runtime+timeslice; runqueue->runedtime=runqueue->killtime+ runqueue->runedtime; runqueue->runtime=runqueue->runedtime; printf(\name %d, runtime=%d, runedtime=%d,killtime=%d(...END...)\\n\ runqueue->name,runqueue->runtime,runqueue->runedtime,runqueue->killtime); } else { runqueue->killtime=timeslice; runqueue->runedtime=runqueue->runedtime+runqueue->killtime; printf(\ name %d ,runtime=%d,runedtime=%d,killtime=%d\\n%untime,runqueue->runedtime,runqueue->killtime); tail->next=runqueue; tail->next=tail; } } } 运行结果:(截图) 四、 实验分析与总结 对实验运行结果进行分析:如果时间片设置值过大或过小,会对进程的调度产生何种影响。 时间片轮转算法调度的过程是首先取就绪队列的队首结点为运行队列的结点,修改就绪队列首指针后移;然后调度运行队列结点,即运行队列结点的要求运行时间减去时间片时间;若修改后要求运行时间<=0,则表示该进程结点运行完毕,修改进程结点的PCB信息,记录runtime,runedtime,killtime等信息,并将该结点置于就绪队列的队尾,等待下次调度,同时修改队尾指针。若就绪队列非空,则继续执行第一步,直至就绪队列为空。 如果时间片设置过大使得每个进程能在一个时间片内完成,时间片轮转算法便退化为FCFS算法,无法满足交互式用户的需求。时间片设置过小,使得有些进程不能在一个时间片内完成,会频繁的发生中断,进程上下文的切换,从而增加系统开销,但有利于短作业。 百度搜索“70edu”或“70教育网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,70教育网,提供经典教育范文实验项目三在线全文阅读。
相关推荐: