OS调度算法实验Word文件下载.docx

上传人:b****3 文档编号:16650509 上传时间:2022-11-25 格式:DOCX 页数:7 大小:15.78KB
下载 相关 举报
OS调度算法实验Word文件下载.docx_第1页
第1页 / 共7页
OS调度算法实验Word文件下载.docx_第2页
第2页 / 共7页
OS调度算法实验Word文件下载.docx_第3页
第3页 / 共7页
OS调度算法实验Word文件下载.docx_第4页
第4页 / 共7页
OS调度算法实验Word文件下载.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

OS调度算法实验Word文件下载.docx

《OS调度算法实验Word文件下载.docx》由会员分享,可在线阅读,更多相关《OS调度算法实验Word文件下载.docx(7页珍藏版)》请在冰豆网上搜索。

OS调度算法实验Word文件下载.docx

每进行一次调度程序都打印一次运行进程、就绪队列、以及各个进程的PCB,以便进行检查。

重复以上过程,直到所要进程都完成为止。

#include<

iostream>

cstdio>

queue>

algorithm>

cmath>

cstring>

stack>

malloc.h>

constintMax=100000;

usingnamespacestd;

typedefstructPCB

{

stringpro_name;

//进程名

intpri_num;

//优先数

intarrive_time;

//到达时间

intrun_time;

//需要运行时间

intcost_time;

//已占用CPU时间

charflag;

//进程状态

intID;

friendbooloperator<

(PCBA,PCBB)//定义优先级pri_num大的在前

{

returnA.pri_num<

B.pri_num;

}

};

PCBp[Max];

priority_queue<

PCB>

que_one;

//优先队列

que_two;

intmain()

intn,m,i,j;

intlen;

intall_time;

//所有进程需要运行的总时间

intnow_time;

//系统当前时间

intpos;

while(true)

len=0;

all_time=0;

now_time=0;

cout<

<

"

请输入进程个数:

"

;

cin>

>

n;

请依次输入:

进程名,优先数,到达时间,需要运行时间"

endl;

for(i=1;

i<

=n;

i++)

p[i].pro_name>

p[i].pri_num>

p[i].arrive_time>

p[i].run_time;

all_time+=p[i].run_time;

p[i].cost_time=0;

p[i].flag='

W'

p[i].ID=i;

que_one.push(p[i]);

/*for(i=1;

que_one.top().pri_num<

que_one.pop();

}*/

while(all_time)

while(!

que_one.empty())

系统当前时间:

now_time<

if(que_one.top().arrive_time<

=now_time)

p[que_one.top().ID].flag='

R'

正在运行的进程:

进程名:

que_one.top().pro_name<

优先数:

到达时间:

que_one.top().arrive_time<

需要运行时间:

que_one.top().run_time<

已经运行时间:

que_one.top().cost_time<

运行状态:

p[que_one.top().ID].flag<

p[que_one.top().ID].cost_time+=1;

all_time-=1;

//que_one.top().cost_time+=1;

if(p[que_one.top().ID].cost_time<

que_one.top().run_time)

p[que_one.top().ID].pri_num-=1;

//que_one.top().pri_num-=1;

que_two.push(p[que_one.top().ID]);

for(i=0;

len;

que_one.push(que_two.top());

que_two.pop();

就绪队列的进程:

//cout<

yes"

yes1"

que_one.top().flag<

que_two.push(que_one.top());

yes2"

que_two.empty())

yes3"

else

yes4"

F'

//que_one.top().flag='

该进程已经运行完毕!

now_time+1<

p[que_one.top().ID].cost_time<

pos=0;

yes5"

pos=1;

break;

len++;

if(pos!

=1)

now_time++;

yes6"

yes7"

所有进程已经运行完毕!

总耗时:

return0;

}

/*

2

D423

B304

3

a343

b101

c264

*/

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

当前位置:首页 > PPT模板 > 节日庆典

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

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