进程调度算法模拟实验报告.docx

上传人:b****3 文档编号:11488323 上传时间:2023-06-01 格式:DOCX 页数:13 大小:21KB
下载 相关 举报
进程调度算法模拟实验报告.docx_第1页
第1页 / 共13页
进程调度算法模拟实验报告.docx_第2页
第2页 / 共13页
进程调度算法模拟实验报告.docx_第3页
第3页 / 共13页
进程调度算法模拟实验报告.docx_第4页
第4页 / 共13页
进程调度算法模拟实验报告.docx_第5页
第5页 / 共13页
进程调度算法模拟实验报告.docx_第6页
第6页 / 共13页
进程调度算法模拟实验报告.docx_第7页
第7页 / 共13页
进程调度算法模拟实验报告.docx_第8页
第8页 / 共13页
进程调度算法模拟实验报告.docx_第9页
第9页 / 共13页
进程调度算法模拟实验报告.docx_第10页
第10页 / 共13页
进程调度算法模拟实验报告.docx_第11页
第11页 / 共13页
进程调度算法模拟实验报告.docx_第12页
第12页 / 共13页
进程调度算法模拟实验报告.docx_第13页
第13页 / 共13页
亲,该文档总共13页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

进程调度算法模拟实验报告.docx

《进程调度算法模拟实验报告.docx》由会员分享,可在线阅读,更多相关《进程调度算法模拟实验报告.docx(13页珍藏版)》请在冰点文库上搜索。

进程调度算法模拟实验报告.docx

进程调度算法模拟实验报告

计算机综合实验报告

 

课程名称操作系统

实验学期至学年第学期

学生所在系部

年级专业班级

学生姓名学号

任课教师

实验成绩

 

信息科学与技术系制

 

实验报告须知

1学生上交实验报告时,必须为打印稿(A4纸)。

页面空间不够,可以顺延。

2学生应该填写的内容包括:

封面相关栏目、实验地点、时间、目的、设备环境、内容、结果及分析等。

3教师应该填写的内容包括:

实验成绩、教师评价等。

 

《操作系统》课程实验报告

实验室:

小型机实验室(二教217)2010年5月4日

实验题目

进程调度算法模拟

一、实验目的

1掌握处理机调度及其实现;

2掌握进程状态及其状态转换;

3掌握进程控制块PCB及其作用

二、设备与环境

1.硬件设备:

PC机或终端一台

2.软件环境:

(说明安装的操作系统环境,如Windows操作系统或者Linux操作系统,介绍相应的开发工具,如vs或vi,gcc,gdb,C等相关的开发工具或平台)。

三、实验内容

1用C语言实现采用先来先服务进程调度算法对10个进程的调度。

2用C语言实现采用高优先权进程调度算法对10个进程的调度。

3用C语言实现采用短作业优先进程调度算法对10个进程的调度。

四、实验结果及分析

1.实验步骤

根据要求大致确定需要用到的函数以及实现方法

写出三个文件的代码

编译,修改语法错误

链接执行,观察结果,查看有无逻辑错误

2.相关数据结构定义

typedefstructnode

{

charname[MAXSIZE];//进程名称

intstate;//0表示进程处于就绪态,1表示进程处于等待态

intprio;//优先级

inttime;//需要在cpu上处理的时间

structnode*next;//链指针

}PCB;

3.实验代码(要求加注释)

voidinsert1(PCB*p,PCB*queue)

{

PCB*q;

q=queue;

while(q->next)

q=q->next;

q->next=p;

p->next=NULL;

}//先来先服务把进程p插入就绪或等待队列的尾部

voidcreat1(intn)

{

PCB*p;

inti;

ready=newPCB;

ready->next=NULL;

wait=newPCB;

wait->next=NULL;//带头结点的队列

run=NULL;

for(i=1;i<=n;i++)

{

p=newPCB;

cout<

";

cin>>p->name;

cout<<"进程状态:

";

p->state=rand()%2;

cout<state;

cout<

if(p->state==0)

insert1(p,ready);//当state为0时,插入到就绪队列中

else

insert1(p,wait);//否则插入到等待队列中

}

}

voidruning()

{

PCB*p;

cout<<"当前执行进程:

";

if(!

run)

cout<<"空"<

";

else

cout<name<

";

if(!

ready->next)

cout<<"空";

else

for(p=ready->next;p;p=p->next)

cout<name<<"";

cout<

";

if(!

wait->next)

cout<<"空";

else

for(p=wait->next;p;p=p->next)

cout<name<<"";

cout<

}

voidFCFS(intn)

{

srand((int)time(0));

intstate_change;

PCB*p;

cout<

creat1(n);

srand((int)time(0));

cout<

"<

runing();

cout<

cout<<"运行中:

"<

while(ready->next||wait->next)

{

if(ready->next)

{

run=ready->next;

ready->next=run->next;

}

runing();

state_change=rand()%2;

cout<

if(state_change==1&&wait->next)

{

p=wait->next;

wait->next=p->next;

insert1(p,ready);

}

run=NULL;

}

cout<

}

//**********************************************************************

voidinsert2(PCB*p,PCB*queue)

{

PCB*q,*preq;

preq=queue;q=queue->next;

while(q&&(q->prio)<=(p->prio))

{

preq=q;

q=q->next;

}

if(!

q)

{

preq->next=p;

p->next=NULL;

}

else

{

p->next=q;

preq->next=p;

}

}//把p插入优先级队列中,队列仍然按照优先级高低排列

voidcreat2(intn)

{

srand((int)time(0));

PCB*p;

run=NULL;

for(inti=0;i

{

p=newPCB;

cout<

";

cin>>p->name;

cout<<"进程状态:

";

p->state=rand()%2;

cout<state;

cout<

";

p->prio=rand()%5+1;

cout<prio;

cout<

";

p->time=rand()%10+1;

cout<time;

cout<

if(p->state==0)

insert2(p,ready);//当state为0时,插入到就绪队列中

else

insert1(p,wait);//否则插入到等待队列中

}

}

voidFPF(intn)

{

srand((int)time(0));

intwait_state_change,run_state_change,cpu_time=rand()%5+1;

//cpu_time表示一次在cpu上的执行时间

PCB*p;

cout<<"************高优先级********************************"<

creat2(n);

srand((int)time(0));

cout<

"<

runing();

cout<

cout<<"运行中:

"<

while(ready->next||wait->next)

{

if(ready->next)

{

run=ready->next;

ready->next=run->next;

}

runing();

wait_state_change=rand()%2;

cout<<"wait_state_change="<

if(wait_state_change==1&&wait->next)

{

p=wait->next;

wait->next=p->next;

insert1(p,ready);

}

if(run&&run->time>cpu_time)

{

run->time-=cpu_time;

run_state_change=rand()%2;

cout<<"run_state_change="<

if(run&&run_state_change==0&&run->time>0)

insert1(run,ready);

else

insert1(run,wait);

}

elserun=NULL;

}

cout<

}

//**********************************************************************

voidinsert3(PCB*p,PCB*queue)

{

PCB*q,*preq;

preq=queue;q=queue->next;

while(q&&(q->time)<=(p->time))

{

preq=q;

q=q->next;

}

if(!

q)

{

preq->next=p;

p->next=NULL;

}

else

{

p->next=q;

preq->next=p;

}

}//把p插入作业按时间排列的队列中,队列仍然按照时间长短排列

voidcreat3(intn)

{

srand((int)time(0));

PCB*p;

run=NULL;

for(inti=0;i

{

p=newPCB;

cout<<"请输入进程名称:

";

cin>>p->name;

cout<<"进程状态:

";

p->state=rand()%2;

cout<state;

cout<

";

p->time=rand()%10+1;

cout<time;

cout<

if(p->state==0)

insert3(p,ready);//当state为0时,插入到就绪队列中

else

insert1(p,wait);//否则插入到等待队列中

}

}

voidSPF(intn)

{

srand((int)time(0));

intstate_change;

PCB*p;

cout<<"***********短作业优先*******************************"<

creat3(n);

cout<

"<

runing();

srand((int)time(0));

cout<

"<

while(ready->next||wait->next)

{

if(ready->next)

{

run=ready->next;

ready->next=run->next;

}

runing();

state_change=rand()%2;

cout<

if(state_change==1&&wait->next)

{

p=wait->next;

wait->next=p->next;

insert1(p,ready);

}

run=NULL;

}

cout<

}

voidmain()

{

intn;

cout<<"请输入进程个数:

";

cin>>n;

cout<

FCFS(n);

FPF(n);

SPF(n);

}

4.实验结果分析

先来先服务FCFS进程调度算法采用非抢占方式,实现方法比较简单,但使短作业和实时性要求较高的作业等待的时间过长;高优先级,此处采用抢占方式,另外还加入了时间片轮转方法;短作业优先方法是一种非抢占方式,没有考虑长作业和实时任务的要求。

五、实验心得

通过这次实验,我在以前学过的知识的基础上有了提高,学到了很多新知识:

比如将用户作业和就绪进程按提交的顺序或变为就绪状态的先后排成队列,并按照先来先服务的方式进行调度。

调度时从后备队列中选择若干优先权最高的个作业进入内存;或从就绪队列中选择优先权最高的进程,将处理机分配给它。

调度时根据估计的运行时间首先调度运行占用CPU时间最短的作业或进程

教师评价

评定项目

A

B

C

D

评定项目

A

B

C

D

算法正确

实验结果正确

程序结构合理

报告规范

综合评定等级

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 其它

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2