高动态优先权优先的进程调度算法模拟Word文档格式.docx
- 文档编号:18102138
- 上传时间:2022-12-13
- 格式:DOCX
- 页数:14
- 大小:452.42KB
高动态优先权优先的进程调度算法模拟Word文档格式.docx
《高动态优先权优先的进程调度算法模拟Word文档格式.docx》由会员分享,可在线阅读,更多相关《高动态优先权优先的进程调度算法模拟Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
●进程在就绪队列中呆一个时间片,优先数增加1;
●进程每运行一个时间片,优先数减3。
(4)假设在调度前,系统中有5个进程,它们的初始状态如下:
ID01234
PRIORITY93830290
CPUTIME00000
NEEDTIME33634
STARTBLOCK2-1-1-1-1
BLOCKTIME30000
STATEREADYREADYREADYREADYREADY
(5)为了清楚地观察进程的调度过程,程序应将每个时间片内的进程的情况显示出来,参照的具体格式如下:
RUNNINGPROCESS:
$id0
READYQUEUE:
$id1->
$id2
BLOCKQUEUE:
$id3->
$id4
FINISHQUEUE:
$id0->
$id1->
$id2->
$id3->
==================================================================
IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME
0XXXXXXXXXXXX
1XXXXXXXXXXXX
2XXXXXXXXXXXX
3XXXXXXXXXXXX
4XXXXXXXXXXXX
====================================================================
4.实验要求
(1)将源程序(priority.c)和程序运行结果写入实验报告。
(2)将该算法执行过程与高响应比优先调度算法的执行过程进行比较。
5.实验过程及结果
(1).代码:
#include<
stdio.h>
string.h>
stdlib.h>
char*State[]={"
READY"
"
RUNNING"
BLOCK"
FINISH"
};
typedefstructPCB
{
intid;
intpriority;
intcputime;
intneedtime;
intstartblock;
intblocktime;
char*state;
structPCB*next;
structPCB*nt;
}PCB;
PCB*Ready,*Block,*Finish,*Runing,*ALL;
PCB*findHighest();
voidinsert(PCB*node,PCB*insert,inti);
voidModifyPriority();
voidModifyBlock();
voidBlockToReady();
voidPrint();
voidFreeAllPCB();
voidinit()
PCB*pro=(PCB*)malloc(sizeof(PCB));
Ready->
next=ALL=pro;
pro->
id=0;
priority=9;
cputime=0;
needtime=3;
startblock=2;
blocktime=3;
pro=pro->
next=pro->
nt=(PCB*)malloc(sizeof(PCB));
id=1;
priority=38;
startblock=-1;
blocktime=0;
id=2;
priority=30;
needtime=6;
id=3;
priority=29;
id=4;
priority=0;
needtime=4;
nt=NULL;
}
PCB*findHighest()
PCB*pro,*highest;
PCB*propre=Ready;
PCB*highpre=Ready;
highest=pro=Ready->
next;
while(pro!
=NULL)
{
if(pro->
priority>
highest->
priority)
{
highest=pro;
highpre=propre;
}
propre=propre->
pro=pro->
}
highpre->
next=highest->
next=NULL;
returnhighest;
voidinsert(PCB*node,PCB*insert,inti)
node->
state=State[i];
next=insert->
insert->
next=node;
voidModifyPriority()
PCB*p;
p=Ready->
while(p!
=NULL)
p->
priority++;
p=p->
voidModifyBlock()
p=Block->
blocktime--;
voidBlockToReady()
PCB*p,*pre,*node;
pre=Block;
p=pre->
if(p->
blocktime==0)
p->
startblock--;
node=p;
p=pre->
next=node->
node->
insert(node,Ready,0);
else{
pre=pre->
p=p->
voidPrint()
PCB*pro,*All;
if(Runing!
=NULL)printf("
RUNNINGPROCESS:
$id%d\n"
Runing->
id);
printf("
READYQUEUE:
"
);
pro=Ready->
printf("
->
$id%d"
pro->
puts("
"
BLOCKQUEUE:
pro=Block->
FINISHQUEUE:
pro=Finish->
===============================================================\n"
IDPRIORITYCPUTIMENEEDTIMESTATESTARTBLOCKBLOCKTIME\n"
All=ALL;
while(All!
{
%d%10d%10d%10d%8s%10d%11d\n"
All->
id,All->
priority,All->
cputime,All->
needtime,All->
state,All->
startblock,All->
blocktime);
All=All->
nt;
voidFreeAllPCB()
free(Finish);
intmain(void)
PCB*pro;
Ready=(PCB*)malloc(sizeof(PCB));
Block=(PCB*)malloc(sizeof(PCB));
Finish=(PCB*)malloc(sizeof(PCB));
Block->
Finish->
init();
while(Ready->
next!
pro=findHighest();
Runing=pro;
pro->
state=State[1];
pro->
cputime++;
needtime--;
if(pro->
startblock>
0)
{
pro->
}
priority-=3;
Print();
ModifyBlock();
ModifyPriority();
BlockToReady();
needtime==0)
insert(pro,Finish,3);
Runing=NULL;
else
if(pro->
startblock==0){
insert(pro,Block,2);
}
else
{
insert(pro,Ready,0);
Print();
FreeAllPCB();
return0;
程序运行结果
(2).试验中的问题将该算法执行过程与高响应比优先调度算法的执行过程进行比较。
为了照顾紧迫型作业,使之在进入系统后便获得优先处理,引入了高优先权优先调度算法。
此算法常被用于批处理系统,作为作业调度算法,也作为多种操作系统中的进程调度算法,还可用于实时系统。
该算法用于作业调度时,系统将从后备队列中选择若干个优先权最高的作业装入内存。
当用于进程调度时,该算法是把处理机分配给就绪队列中优先权最高的进程。
动态优先权是指在创建进程时所赋予的优先权,是可以随进程的推进或随其等待时间的增加而改变的,以便获得更好的调度性能。
6.实验中的问题及心得
动态高优先权优先算法非常适合用在批处理操作系统中,而且也可以用在实时系统中,具有非常好的作用。
实验过程中遇到了很多的问题也发现了自己的不足,C语言的功底还是不行啊,编程过程总是不知哪里出错,好在有同学帮助,问题总算得以解决,C语言还要学习啊,以后要复习一下编程语言,不能再在编程上出问题了,相信在以后的实验里,会有更大的收获。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 动态 优先权 优先 进程 调度 算法 模拟