武汉轻工大学实验一进程调度Word格式文档下载.doc

上传人:b****2 文档编号:14625056 上传时间:2022-10-23 格式:DOC 页数:10 大小:143.54KB
下载 相关 举报
武汉轻工大学实验一进程调度Word格式文档下载.doc_第1页
第1页 / 共10页
武汉轻工大学实验一进程调度Word格式文档下载.doc_第2页
第2页 / 共10页
武汉轻工大学实验一进程调度Word格式文档下载.doc_第3页
第3页 / 共10页
武汉轻工大学实验一进程调度Word格式文档下载.doc_第4页
第4页 / 共10页
武汉轻工大学实验一进程调度Word格式文档下载.doc_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

武汉轻工大学实验一进程调度Word格式文档下载.doc

《武汉轻工大学实验一进程调度Word格式文档下载.doc》由会员分享,可在线阅读,更多相关《武汉轻工大学实验一进程调度Word格式文档下载.doc(10页珍藏版)》请在冰豆网上搜索。

武汉轻工大学实验一进程调度Word格式文档下载.doc

有n个进程处于就绪状态,有m个进程处于阻塞状态。

采用轮转法进程调度算法进行调度(调度过程中,假设处于执行状态的进程不会阻塞),且每过t个时间片系统释放资源,唤醒处于阻塞队列队首的进程。

程序要求如下:

1)输出系统中进程的调度次序;

2)计算CPU利用率。

3、实验环境

Windows操作系统、VC++6.0

C语言

4、设计思想:

unuse_cpu++

x++

x==t

blocked队首进程入ready队列队尾;

x=0

begin

use_cpu=0

unuse_cpu=0

ready队列不空或blocked队列不空

ready队列不空

取ready队首元素

p->

PCB.state置“运行”

输出p->

PCB.name

PCB.cpu_time--

use_cpu++

PCB.cpu_time>

p入ready队列队尾

释放p

end

/*use_cpu中记录CPU运行时间

/*unuse_cpu中记录CPU空闲时间

是 否

5、源程序

#include<

stdio.h>

stdlib.h>

structPCB_type

{

charname;

//进程名

intstate;

//进程状态

intcpu_time;

//运行需要的CPU时间(需运行的时间片个数)

};

structQueueNode

{

structPCB_typePCB;

structQueueNode*next;

structQueueNode *ready_head=NULL,//就绪队列队首指针

*ready_tail=NULL,//就绪队列队尾指针

*blocked_head=NULL,//阻塞队列队首指针

*blocked_tail=NULL;

//阻塞队列队尾指针

intinuse_cpu,outuse_cpu;

voidstart_state()//读入假设的数据,设置系统初始状态

intn,m,i;

structQueueNode*p,*q;

printf("

假设处于就绪状态的进程数n为:

\n"

);

scanf("

%d"

&

n);

假设处于阻塞状态的进程数m为:

m);

p=(structQueueNode*)malloc(sizeof(structQueueNode));

p->

next=NULL;

ready_head=ready_tail=p;

for(i=1;

i<

=n;

i++)

{

p=(structQueueNode*)malloc(sizeof(structQueueNode));

p->

PCB.state=1;

printf("

请输入就绪程序%d的[名称]和[CPU时间]:

i);

scanf("

%d%d"

PCB.name,&

PCB.cpu_time);

ready_tail->

next=p;

ready_tail=p;

}

q=(structQueueNode*)malloc(sizeof(structQueueNode));

q->

blocked_head=blocked_tail=q;

=m;

q=(structQueueNode*)malloc(sizeof(structQueueNode));

q->

PCB.state=0;

请输入阻塞进程%d的[名称]和[CPU时间]:

q->

blocked_tail->

next=q;

blocked_tail=q;

\n当前处于就绪状态的进程有:

\n"

p=ready_head->

next;

i=1;

while(p)

进程%d的[名称]和[状态]和[CPU时间]:

%5d%5d%5d\n"

i,p->

PCB.name,p->

PCB.state,p->

p=p->

i++;

}

voiddispath()//模拟调度

inta=0,t;

inuse_cpu=0;

outuse_cpu=0;

请输入时间片t:

"

t);

开始调度:

while(ready_head!

=ready_tail||blocked_head!

=blocked_tail)

structQueueNode*p,*q;

if(ready_head!

=ready_tail)

{

p=ready_head->

ready_head->

next=p->

p->

if(ready_head->

next==NULL)

{

ready_tail=ready_head;

}

PCB.state=2;

printf("

\t进程%d调度中"

p->

PCB.name);

inuse_cpu++;

a++;

PCB.cpu_time--;

if(p->

PCB.cpu_time)

ready_tail->

ready_tail=p;

else

printf("

\t进程%d完成调度!

"

free(p);

}

else

outuse_cpu++;

\t空闲一个时间片"

if(a==t&

&

blocked_head!

q=blocked_head->

blocked_head->

next=q->

q->

if(blocked_head->

blocked_tail=blocked_head;

ready_tail->

ready_tail=q;

a=0;

voidcalculate()//计算CPU利用率

\nCPU的利用率为:

%.2f\n"

(float)inuse_cpu/(inuse_cpu+outuse_cpu));

voidmain()

start_state();

dispath();

calculate();

6、实例运行结果

7、总结

该实验利用进程调度中的优先级算法调度进程,开始给每一个进程设定一个优先级数,对于优先级高的进程先调度,优先级低的进程后调度,在调度一个进程时,其他进程将处于就绪态,而正在被调度的进程应处于运行态。

一开始在做这个实验的时候,我感觉大脑一片空白,不知道该从哪里动笔。

后来根据书上的内容和从网上下载的资料,我慢慢地了解了大致的流程。

通过这次实验,首先加深了我对进程调度方法和功能的认识,其次让我更加深刻地理解了操作系统中进程调度中优先级调度的基本原理。

优先级调度算法只是进程调度算法的一种,我们还应依照书本去学习进程调度的其它算法,以便更好地了解进程调度。

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

当前位置:首页 > 高中教育 > 高考

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1