操作系统课设进程调度模拟程序文档格式.docx

上传人:b****2 文档编号:4193606 上传时间:2023-05-02 格式:DOCX 页数:27 大小:115.37KB
下载 相关 举报
操作系统课设进程调度模拟程序文档格式.docx_第1页
第1页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第2页
第2页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第3页
第3页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第4页
第4页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第5页
第5页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第6页
第6页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第7页
第7页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第8页
第8页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第9页
第9页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第10页
第10页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第11页
第11页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第12页
第12页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第13页
第13页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第14页
第14页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第15页
第15页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第16页
第16页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第17页
第17页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第18页
第18页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第19页
第19页 / 共27页
操作系统课设进程调度模拟程序文档格式.docx_第20页
第20页 / 共27页
亲,该文档总共27页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

操作系统课设进程调度模拟程序文档格式.docx

《操作系统课设进程调度模拟程序文档格式.docx》由会员分享,可在线阅读,更多相关《操作系统课设进程调度模拟程序文档格式.docx(27页珍藏版)》请在冰点文库上搜索。

操作系统课设进程调度模拟程序文档格式.docx

图1一2FCFS算法流程图

No4

图1一3RR算法流用图

No5

图1一4HPF算法流卅图

Nob

四.源程序及注

Tr

pcbobj.h

#include<

string>

usingnamespacestd;

#ifndefPCBOBJ_H_

#definePCBOBJ_H_

enumpStaUis{Wait,Run,Finish,UNGO}"

/定义进程的四种状态

classPCBobj{

public:

PCBobj();

PCBobj(stringnamejntidjntreachjntexecute);

virtual-PCBobjO;

intgetExecTime()const;

intge(HasExecTime()const;

intgetld()const;

intgetReachTinie()const;

siringgetName()const;

pStalusgetStatus()const;

voidsetHasExecTime(inthasExecTime);

voidsetld(intpld);

voidsetStatus(pStatusstatus);

voidsetExecTime(intexecTime);

voidsetName(stringpName);

voidsetReachTime(intreachTime);

boolisFinish();

〃进程是否运行完毕

boollast_statu;

//^l]断进程上一个cpu是否是运行态

private:

stringpName;

〃进丹名

in(pld;

〃进秤优先数

intreachTime;

〃进軒•到达时间

intexecTime;

〃进杆1•需要运彳j:

的时间

inihasExecTime;

//进程lL经运彳J:

pStalusstatus;

};

typedefPCBobj*pcbobj;

#endif/*PCBOBJ_H_*/

pcbobj.cpp代码include”PCBobj.h”

PCBobj:

:

PCBobj(){

hasExecTime=O;

沈阳理「•人学

status=UNGO;

last_statu=false;

PCBobj(stringnamejntidjntreachjntexecute)!

pName=name;

pld=id;

reachTime=reach;

execTime=execuie;

status=UNGO:

}

-PCBobj(){}

intPCBobj:

getExecTime()const{

returnexecTime;

getHasExecTime()const{returnhasExecTime;

ge(Id()const{

returnpld;

stringPCBobj:

gelName()const{

returnpName;

getReachTime()const{

returnreachTime;

pStatusPCBobj:

getStatus()const{

returnstatus;

voidPCBobj:

setHasExecTime(inthasExecTime){this->

hasExecTime=hasExecTime;

setId(intpld){this->

pld=pld;

setStatus(pStatusstatus)!

this->

status=status;

setExecTime(intexecTime){this->

execTime=execTime;

setName(stringpName){lhis->

pName=pName;

setReachTime(intreachTime){this->

reachTime=reachTime;

boolPCBobj:

isFinish(){

boolFlag=false;

if(execTime==hasExecTime){slatus=Finish;

Flag=true;

returnFlag;

waitmanager.h#include<

iostream>

list>

#includeHPCBobj.hM

#ifndefWAITMANAGER.H.

#defineWAITMANAGER_H_

classWaitManager{

WaitManager();

virtual-WaitManager();

voidadd(pcbobjnew_obj);

voidinsert(pcbobjnew_name);

voidremove(stringname);

voidremove();

boolemptyO;

pcbobjget();

pcbobjlast();

list<

pcbobj>

wait.PCBJist;

);

#endif/*WAITMANAGER.H.♦/

waitmanager.cpp-#includeHWaitManager.hH

WaitManager:

WaitManager(){}WaitMana2er:

>

WaitManager(){}voidWaitManager:

add(pcbobjnew_obj){

wait_PCB」ist.push_back(new_obj);

new_obj->

setStatus(Wait);

boolWaitManager:

en】ply(){

returnwait_PCB」is(・cmply();

voidWaitManager:

insert(pcbobjnew_obj){

if(wail_PCBJist.emptyO)

{

add(new_obj);

}else{

boolinsertJnfo=false;

//t*t看是古己经插入进去

for(Iist<

iteratorit=waitJPCB_list.begin();

it!

=waitJPCBJist.end();

it++){

if(new_obj->

getld()>

(*it)->

getld()){

wait_PCBJist.insert(it,new_obj);

ncw^obj・>

sc(SkHus(Wait);

insert」nfo=l「ue;

break;

if(!

insert」nfo){

wait_PCBJist.push_back(new_obj);

new_obj->

remove(stringname){

if(empty()){

coutvv”没有进程在就绪队列屮”vvendl;

}else

boolremovefo=false;

for(list<

iteratorit=wait_PCBJist.begin();

=wait_PCBJist.end();

it++){if((*it)->

getName()==name){

wail_PCBJist.erase(it);

remove_info=tme;

removejnfo){

cout«

name«

H进程《不存在H«

endl;

remove(){

coutvv”没有就绪进程在队列+M«

wait_PCBJist.pop_front();

pcbobjWaitManager:

get(){

returnwait_PCBJist.front();

last(){

returnwait.PCBJist.back();

pumanagcr.h-

#includePCBobj.hn

#ifndefCPU_MANAGER

#defineCPU_MANAGER_H_

enumcpu.Status{FREE.BUSY}^/cpu的状态classcpu_Manager{

cpu_Manager();

virtual~cpu_Manager();

voidremove();

cpu^StatusgetCpuJnfo()const;

pcbobjgetCpu_pcb()const;

voidadd(pcbobjcpu_pcb);

voidupdate();

voidupdate(intargs);

intcpu_timeslice;

cpu.Statuscpujnfo;

pcbobjcpu_pcb;

#endif/*CPU_MANAGER_H_*/

cpumanager.cpp-#includencpu_Manager.hH

cpu_Manager:

cpu_Manager(){

cpu_pcb=();

cpu_info=FREE;

cpu_timeslice=4;

cpu_pcb=O;

cpu_Statuscpu_Manager:

getCpu_info()const{

returncpujnfo;

pcbobjcpu^Manager:

getCpu_pcb()const{returncpu_pcb;

voidcpu_Manager:

add(pcbobjcpu_pcbl){cpu_pcb=cpu_pcbI;

cpuJnfo=BUSY;

voidcpu_Manager:

remove(){this->

cpu_info=FREE;

update(){cpu_pcb->

setStatus(Run);

cpu_pcb->

setHasExecTime(

cpu_pcb->

getHasExecTime()+l);

update(intargs){

update();

setld(cpu_pcb->

getld()-args);

scheduLsimulate.h

#include"

WaitManager.h0

#includeHcpu_Manager.hH

#ifndefSCHEDUL_SIMULATE_H_

#defineSCHEDUL_SIMULATE_H_

voidchoice();

stringconvert_statu(pStatusstatu);

voidprocess_init(pcbobjprocess);

voidprocess_update(pcbobjprocessjnttime_record,WaitManager&

wait_manager);

voidprocess_update」d(pcbobjprocessJnttime_record,WaitManager&

//——打印进程信息

voidprocess_record(pcbobjprocessJnttime.record);

//从wait至ljrunvoidwaitTOrun(WaitManager&

wait_manager,cpu_Manager&

cpu_manager);

voidrunTOwail(WaitManager&

cpu_nianager);

voidFCFS(pcbobjprocess);

voidRR(pcbobjprocess);

voidHPF(pcbobjprocess);

#endif/*SCHEDUL_SIMULATE_H_♦/

scheduLsimulate.cpp

#incIudeHscheduLsimulate.hH

voidchoice(){

NoI2

nl:

FCFSn«

endI;

n2:

RRH«

n3:

HPF,,«

cou(v<

”4:

quir‘vvendl;

stringconvert_statu(pStatusstatu){

stringvalue=f,UNGOH;

switch(statu){

caseWait:

value=”Wait”;

caseRun:

value="

Run"

;

caseFinish:

Finish"

caseUNGO:

UNGO”;

returnvalue;

voidprocess.init(pcbobjprocess){

stringname;

intprocess.id;

intprocess^reach;

intprocess_execute;

cout«

"

请按顺序输入进程的唯一标识…进程名进程的优先级进程的到达时间进程的运行时间"

«

endl;

for(inti=0;

i<

4;

i++){

//process里的hasExecTime和status己经被初始化

请输入第"

vv(i+1)«

个进程的信息"

cin»

name;

processjd;

process^reach;

pr(Kess_execute;

(process+i)->

setName(name);

setId(process.id);

(process+i)->

setReachTime(process_reach);

setExecTime(process_execute);

”第”«

(i+1)«

”个进稈信息已经初始化,,«

endl:

所有进程信息已经全部完成«

NoI3

voidprocess_update(pcbobjprocess,inttime_record,WaitManager&

wait_manager){for(inti=0;

if((process+i)->

getReachTime()==time_record){wait_manager.add((process+i))y/H接加到末尾

voidprocess_update.id(pcbobjprocess,inttime_record,WaitManager&

wait_manager){

getReachTime()==time.record){

waiLmanager.insert((process+i));

voidprocess_record(pcbobjprocess,inttime_record)

时亥ij:

"

«

time_record«

”进程名\l优先数\t到达时间\(运行时间\t已经运行时间\t状态"

cout«

••H

iv4;

(process+i)->

getName()«

M\tH

getld()«

H\tH

getReachTime()«

°

\tH

getExecTime()«

H\tH

getHasExecTime()«

M\t\tn;

if((process+i)->

Iast_statu)

convert_statu(Run)«

else

convert_statu((process+i)->

getStatus())«

(process+i)->

lascsta(u=false;

•'

'

'

voidwaitTOrun(WaitManager&

wait_manager,cpu_Manager&

cpu.manager){cpu_manager・add(wait_manager.get());

wait_manager.remove();

voidrunTOwait(WaitManager&

cpu_manager){pcbobj(emp=cpu_managc「・gelCpu_pcb();

temp->

last_statu=true;

wait_manager.add(temp);

voidFCFS(pcbobjprocess){

inttimc_record=0;

PCBobj*process_last=process+3;

WaitManagerwait_manager;

cpu^Managercpumanager;

while(processJast->

getStatus()!

=Finish){process_update(process,time_record,wait_manager);

proccss_rccord(proccss,timc_rccord);

if(!

wait_manager.empty()&

&

cpumanager.getCpu_info()==FREE){waitTOrun(wait_manager,cpumanager);

if(cpumanager.getCpufo()==BUSY){

cpumanager.update();

if(cpumanager.getCpu_pcb()->

isFinish())cpumanager.removeO;

time_record++;

if(process_last->

=UNGO&

!

wait_manager.empty())//L2经到达{process.last=wait.manager.Iast();

process_record(process,time_record);

voidRR(pcbobjprocess){

inttime_record=0;

cpu_Managercpumanager;

intk=();

//记录时间片满则为零

=Finish){

process_update(process,time_record,wait_manager);

process_record(processJime_record);

cpumanager.getCpu」nfo()==FREE){waitTOrun(wait_manager,cpumanager);

cpunianager.

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

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2