操作系统处理机调度实验报告Word文档格式.docx
《操作系统处理机调度实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《操作系统处理机调度实验报告Word文档格式.docx(14页珍藏版)》请在冰豆网上搜索。
intpriority;
intcputime;
intneedtime;
intcount;
enumstateprocess;
structpcbb*next;
typedefstructpcbbpcb;
voiddisplay_menu(){
printf("
CHOOSETHEALGORITHM:
\n"
);
1PRIORITY\n"
2ROUNDROBIN\n"
3EXIT\n"
}
pcb*get_process(){
pcb*q;
pcb*p;
pcb*t;
inti=0;
inputnameandtime\n"
while(i<
P_NUM){
q=(pcb*)malloc(sizeof(pcb));
scanf("
%s"
q->
name);
%d"
&
q->
needtime);
q->
cputime=0;
priority=P_TIME-q->
needtime;
process=ready;
next=NULL;
if(i==0){
p=q;
t=q;
}
else{
t->
next=q;
i++;
}
returnp;
voidfree_process(pcb*p){
while(p!
=NULL){
q=p;
p=p->
next;
free(q);
voiddisplay(pcb*p){
namecputimeneedtimeprioritystate\n"
while(p){
printf("
p->
"
cputime);
priority);
switch(p->
process){
caseready:
printf("
ready\n"
break;
caseexecute:
execute\n"
break;
caseblock:
block\n"
casefinish:
finish\n"
intprocess_finish(pcb*q){
intb1=1;
while(b1&
&
q){
b1=b1&
needtime==0;
q=q->
returnb1;
voidcpuexe(pcb*q){
pcb*t=q;
inttp=0;
while(q){
if(q->
process!
=finish){
q->
if(q->
needtime==0){
q->
process=finish;
}
if(tp<
priority&
tp=q->
priority;
if(t->
needtime!
=0){
t->
priority-=3;
needtime--;
process=execute;
cputime++;
voidpriority_cal(){
p=get_process();
intcpu=0;
while(!
process_finish(p)){
cpu++;
cputime:
%d\n"
cpu);
cpuexe(p);
display(p);
sleep
(2);
free_process(p);
Allprocesseshavefinished\n"
pcb*get_process_round(){
while(i<
P_NUM){
count=0;
voidcpu_round(pcb*q){
if(q->
needtime==1)
q->
else
cputime+=2;
needtime-=2;
needtime<
0){
needtime=0;
count++;
pcb*get_next(pcb*k,pcb*head){
t=k;
do{
t=t->
}while(t&
t->
process==finish);
if(t==NULL){
t=head;
while(t->
next!
=k&
process==finish){
t=t->
}}
returnt;
voidset_state(pcb*p){
if(p->
needtime==0){
p->
process==execute){
}}
voiddisplay_round(pcb*p){
namecputimeneedtimecountstate\n"
count);
voidround_cal(){
pcb*r;
p=get_process_round();
r=p;
if(r->
cpu+=1;
else
cpu+=2;
cpu_round(r);
r=get_next(r,p);
display_round(p);
set_state(p);
main(){
display_menu();
intk;
scanf("
k);
switch(k){
case1:
priority_cal();
case2:
round_cal();
case3:
default:
YOUHAVENOTCHOOSEANYALGORITHM!
运行后结果如下:
[root@rhel5hbzy~]#gcc-ochulijichuliji.c
[root@rhel5hbzy~]#./m
1PRIORITY
2ROUNDROBIN
3EXIT
1
inputnameandtime
jing2
aaaa8
bbbb5
ffff4
ggg6
namecputimeneedtimeprioritystate
jing-1145execute
aaaa*0842ready
bbbb20050finish
ffff20050finish
ggg0644ready
rtyucputime:
2
jing*2042execute
5cputime:
3
jing*2042finish
ggg1541execute
2cputime:
4
aaaa'
1739execute
ggg1541ready
5
1739ready
ggg2438execute
6
aaaa$2636execute
ggg2438ready
7
aaaa$2636ready
ggg3335execute
8
aaaa!
3533execute
ggg3335ready
9
3533ready
ggg4232execute
10
aaaa4430execute
ggg4232ready
11
aaaa4430ready
ggg5129execute
12
aaaa_5327execute
ggg5129ready
13
aaaa_5327ready
ggg6026execute
14
aaaa_6224execute
ggg6026finish
15
aaaa_7121execute
16
aaaa_8018execute
Allprocesseshavefinished
[root@rhel5hbzy~]#rtyu2
bash:
rtyu2:
commandnotfound
[root@rhel5hbzy~]#3
3:
三、分析与体会
多道程序设计中,通常是若干个进程同时处于就绪状态,必须依照某种策略来决定哪个进程优先占有处理机。
因而引起进程调度。
本实验模拟单处理机情况下的处理机调度问题,使我加深了对进程调度的理解。
通过本次试验,使我加深了对进程调度的具体细节的理解,掌握LINUX系统结构、实现处理机和各种典型的算法,系统了解了操作系统的设计和实验思路,动手能力更强了。