进程调度实验报告文档格式.docx
《进程调度实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《进程调度实验报告文档格式.docx(12页珍藏版)》请在冰豆网上搜索。
1.等待态:
等待某个事件的完成;
2.就绪态:
等待系统分配处理器以便运行;
3.运行态:
占有处理器正在运行。
运行态-等待态往往是由于等待外设,等待主存等资源分配或等待人工干预而引起的。
等待态-就绪态则是等待的条件已满足,只需分配到处理器后就能运行。
运行态-就绪态不是由于自身原因,而是由外界原因使运行状态的进程让出处理器,这时候就变成就绪态。
例如时间片用完,或有更高优先级的进程来抢占处理器等。
就绪态-运行态系统按某种策略选中就绪队列中的一个进程占用处理器,此时就变成了运行态
5)实验过程描述
a)打开MicrosoftVisualC++6.0,创建工程。
b)根据要求用c语言代码实现应用程序,并调试完成
c)运行程序,根据提示输入相应的字符。
d)输入实验测试内容,并观察执行窗口显示的过程。
e)重复c、d过程,认真体会领悟。
6)实验代码//Iss.cpp:
Definestheentrypointfortheconsoleapplication.//
#include"
stdafx.h"
#include<
stdlib.h>
#includevconio.h>
iostream.h>
windows.h>
#defineP_NUM3#defineP_TIME50enumstate{ready,execute,block,finish
};
struct
pcb{
charname[4];
int
priority;
cputime;
needtime;
count;
round;
stateprocess;
pcb
*next;
pcb*get_process()
{_
pcb*q;
pcb*t;
pcb*p;
inti=0;
t=(structpcb*)malloc(sizeof(pcb));
p=(structpcb*)malloc(sizeof(pcb));
cout<
<
"
InputNameandTime"
<
endl;
while(i<
P_NUM)
q=(structpcb*)malloc(sizeof(pcb));
cin>
>
q->
name;
cputime=O;
priority=P_TIME-q->
process=ready;
next=NULL;
if(i==0)
{
p=q;
t->
next=q;
}
else
next=t->
next;
t=q;
q=p;
i++;
returnp;
voiddisplay(pcb*p)
"
cout«
name"
cputime"
needtime"
priority"
state"
while(p)
cout<
p->
;
switch(p->
process)
caseready:
ready"
break;
caseexecute:
execute"
caseblock:
block"
casefinish:
finish"
p=p->
intprocess_finish(pcb*q)
intb1=1;
while(b1&
&
q)
b1=b1&
needtime==O;
q=q->
returnb1;
voidcpuexe(pcb*q)
pcb*t=q;
inttp=0;
while(q)
if(q->
process!
=finish)
{q->
needtime==0)
process=finish;
if(tp<
priority&
=finish){
tp=q->
t=q;
}q=q->
if(t->
needtime!
=0)
{t->
priority-=3;
t->
needtime--;
process=execute;
cputime++;
voidpriority_cal()
pcb*p;
system("
cls"
);
P=get_process();
intcpu=0;
system("
while(!
process_finish(p))
cpu++;
cuptime:
cpu<
cpuexe(p);
display(p);
Sleep(1000);
printf("
Allprocesseshavefinished,pressanykeytoexit"
);
getch();
voiddisplay_menu()
\nCHOOSETHEALGORITHMKendl;
1PRIORITY"
«
endl;
2roundrobin"
3EXIT"
}//显示调度算法菜单,可供用户选择优先权调度算法和时间轮转调度算法
pcb*get_process_round()
{一一
p=(structpcb*)malloc(sizeof(pcb));
inputnameandtime"
cputime=0;
round=0;
count=0;
q=p;
voidcpu_round(pcb*q)
cputime+=2;
needtime-=2;
needtime<
0)
needtime=0;
count++;
round++;
q->
pcb*get_next(pcb*k,pcb*head)
pcb*t;
t=k;
do{
t=t->
while(t&
process==finish);
if(t==NULL)
t=head;
while(t->
next!
=k&
process==finish)
}returnt;
}voidset_state(pcb*p)
if(p->
//如果所需执行时间为0,则设置运行状态为结束
process==execute)
{p->
//如果未执行状态则设置为就绪
}//设置队列中进程执行状态
voiddisplay」ound(pcb*p)
coutvv"
NAME<
QPUTIME<
V"
vv"
NEEDTIME<
'
COUNT<
’ROUND"
STATE'
;
count;
round;
caseexecute:
casefinish:
}p=p->
}〃时间片轮转调度算法输出调度信息
voidround_cal()
pcb*r;
P=get_process_round();
r=p;
cpu+=2;
cpu_round(r);
r=get_next(r,p);
cpu"
display_round(p);
set_state(p);
intmain(intargc,char*argv[])
display_menu();
intk;
scanf("
%d"
&
k);
while
(1)
switch(k){
case1:
priority_cal();
case2:
round_cal();
case3:
return0;
scanf("
\n本调度算法成功结束!
\n;
return0;
7)实验结果截图
g作系统上机\lss\Debug\lss.eze
eputime-1
nameeputine
needtime
prioritysta
A1
1135
execute
eputine
nameeputime
prioritystate
a2
1032
cputime:
3
nameeputime
prioritystate
a3
929
cputime:
4
needtine
a4
826
eputinc-5
Inameeputime
卜5
723
leputime
InameCputime
ine
priorityState
U6
620
eputirie:
7
namQcpu,tine
A7
517
eputime-S
a8
414
exedutft
eputime:
9
namecputime
needtime
鬲?
311
eputline:
18
nan?
cpu,tine
need^inc
pr*ioi*itysta七日
a10
28
execu
eputime-11
11
1S
eputime:
12
a12
02
havefinishcd,pressan*/keytoexit
Allprocesses
CHOOSETHEALGORITHM:
1PRIORITY
2POUNVROBIN
3EXIT
►J
8)对实验的总结
本次实验,任务是用c语言代码实现进程调度模拟系统,从而观察进程的运行过程及加深对进程的了解。
这次实验,加深了我对进程概念及进程调度的理解;
熟悉了进程调度算法。
使得理论知识得到的实践,也使我的编程能力得到了进一步提高。
实验中,我们小组共同学习、共同努力,虽然在实验中遇到了一些问题,但在查阅资料后都解决了。
实验过程也让我认识到自己的不足,好多知识已经模糊不清,在今后自己要多一些实验及相关的小项目,来提高自己的编程能力。