24李后浪 实验四进程调度Word文件下载.docx

上传人:b****4 文档编号:16349287 上传时间:2022-11-23 格式:DOCX 页数:15 大小:198.15KB
下载 相关 举报
24李后浪 实验四进程调度Word文件下载.docx_第1页
第1页 / 共15页
24李后浪 实验四进程调度Word文件下载.docx_第2页
第2页 / 共15页
24李后浪 实验四进程调度Word文件下载.docx_第3页
第3页 / 共15页
24李后浪 实验四进程调度Word文件下载.docx_第4页
第4页 / 共15页
24李后浪 实验四进程调度Word文件下载.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

24李后浪 实验四进程调度Word文件下载.docx

《24李后浪 实验四进程调度Word文件下载.docx》由会员分享,可在线阅读,更多相关《24李后浪 实验四进程调度Word文件下载.docx(15页珍藏版)》请在冰豆网上搜索。

24李后浪 实验四进程调度Word文件下载.docx

stdio.h>

#include<

dos.h>

stdlib.h>

conio.h>

iostream.h>

#defineP_NUM5

#defineP_TIME50

enumstate{

ready,

execute,

block,

finish

};

structpcb{

charname[4];

intpriority;

intcputime;

intneedtime;

intcount;

intround;

stateprocess;

pcb*next;

pcb*get_process();

pcb*get_process(){

pcb*q;

pcb*t;

pcb*p;

inti=0;

cout<

<

"

inputnameandtime"

endl;

while(i<

P_NUM){

q=(structpcb*)malloc(sizeof(pcb));

cin>

>

q->

name;

needtime;

q->

cputime=0;

priority=P_TIME-q->

process=ready;

next=NULL;

if(i==0){

p=q;

t=q;

}

else{

t->

next=q;

i++;

}//while

returnp;

}

voiddisplay(pcb*p){

name"

"

cputime"

needtime"

priority"

state"

while(p){

cout<

p->

;

cputime;

priority;

switch(p->

process){

caseready:

cout<

ready"

break;

caseexecute:

execute"

caseblock:

block"

casefinish:

finish"

p=p->

next;

}

intprocess_finish(pcb*q){

intbl=1;

while(bl&

&

q){

bl=bl&

needtime==0;

q=q->

returnbl;

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->

if(t->

needtime!

=0){

t->

priority-=3;

needtime--;

process=execute;

cputime++;

voidpriority_cal(){

pcb*p;

p=get_process();

intcpu=0;

while(!

process_finish(p)){

cpu++;

cputime:

cpu<

cpuexe(p);

display(p);

printf("

Allprocesseshavefinished,pressanykeytoexit"

);

getch();

voiddisplay_menu(){

CHOOSETHEALGORITHM:

1PRIORITY"

2ROUNDROBIN"

3EXIT"

pcb*get_process_round(){

round=0;

count=0;

voidcpu_round(pcb*q){

q->

cputime+=2;

needtime-=2;

if(q->

needtime<

0){

needtime=0;

count++;

round++;

pcb*get_next(pcb*k,pcb*head){

pcb*t;

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->

p->

process==execute){

voiddisplay_round(pcb*p){

NAME"

CPUTIME"

NEEDTIME"

COUNT"

ROUND"

STATE"

count;

round;

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);

voidmain(){

display_menu();

intk;

scanf("

%d"

&

k);

switch(k){

case1:

priority_cal();

case2:

round_cal();

case3:

display_menu();

scanf("

源程序优先数算法运行得到的结果:

源程序轮转算法运行得到的结果:

程序修改后,优先数算法中,优先级为200,时间片为24,在轮转算法中,固定时间片为24:

根据学号进行程序修改后程序运行图:

程序修改内容对比:

修改后

修改后修改前

结论:

通过本次验证性实验,让我理解了操作系统在运行多个进程时,是如何进行调度的,如何运用时间片与优先级来控制进程运行一次所花的时间和多个程序并行时应该先运行哪个程序。

当然在实验中也遇到了许多问题,比如初次改程序之后,程序执行完之后没有变成finish以及进程每运行一次后所需时间并不是减小24等。

.最终我仔细观察程序,找到应该修改finish的地方,添加语句t->

process=finish程序执行完之后能输出finish,修改所需时间q->

needtime-=24,使进程每执行一次后所需时间的大小都会减小24。

指导教师批阅及成绩:

指导老师签名:

李芳

2014年5月10日

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

当前位置:首页 > 表格模板 > 合同协议

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

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