下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 操作系统进程调度模拟实验

操作系统进程调度模拟实验.doc

操作系统进程调度模拟实验

Elden宋
2017-10-07 0人阅读 举报 0 0 暂无简介

简介:本文档为《操作系统进程调度模拟实验doc》,可适用于综合领域

操作系统进程调度模拟实验ø̵ÈÄÄâʵÑéʵÑéĵÄÍýÔø̵ÈËãµÄÄÄâÓÉîÔøÌÅÄîºÍø̵Èý̵ÄÀíâʵÑéÄÚÈÝÓÃCÓïÑÔPascalÓïÑÔòÆäËûªßʵÏÖÔNN=öø̵ĵÈÄÄâÒªÇóÖÁÉÙÉÓÃÁÖÖ͵ĵÈËãÈçòµÂÖתRoundRobinºÍÓÅÏÈÈßÕßÓÅÏÈËãHighestPriorityFirstÖðøÐÐÄÄâµÈÃöÓÃÀêÊø̵ÄøÌØÖÆéPCBÓÃáÇÂÀÃèÊöùÝÐèÒªËüüÀÒÔÏÂ×ÖκøÌêÊÊýIDøÌÓÅÏÈÊýPriorityæÓÅÏÈÊýÔóµÄøÌÆäÓÅÏÈÈÔßÉÓÃòµÂÖתÊÃ×ÖÎÎÞÓÃøÌÒÑ,ÕÓõÄCPUÊäCPUTIMEÒÔÊäÆΪµÎÏÂÍøÌÐèÕÓõÄCPUÊäALLTIMEµøÌÔËÐÐÍêÏÊALLTIMEäΪø̵Ä×èÈûÊäSTARTBLOCKíʵøÌÔÙÔËÐÐSTARTBLOCKöÊäƺóøÌøÈë×èÈû×ÌøÌ×èÈûµÄÊäBLOCKTIMEíÊÒÑ,×èÈûµÄøÌÔÙµÈýBLOCKTIMEöÊäƺóתÉÍÐ×ÌøÌ×ÌSTATEÓÁÐÖÕëNEXTÓÃÀPCBÅÅÉÓÁÐÓÅÏÈÊýÄäµÄÔ,ÔòÉÓÃòµÂÖתÊÃ×ÖÎÎÞÓúøÌÔÚÍÐÓÁÐÖеÈýÒöÊäÆÓÅÏÈÊýÔöÓøÌÃÔËÐÐÒöÊäÆÓÅÏÈÊýõÙÉèÔÚøÐеÈÇϵÍÖÐÓÐöøÌËüÃǵÄõÊ×ÌÉÒÔàÌÊäÈëüßÓÐÁéîÐÔÒÉÒÔõÊΪÈçÏÂÄÚÈݺIDPRIORITYCPUTIMEALLTIMESTARTBLOCKBLOCKTIMESTATEREADYREADYREADYREADYREADYΪÁËÇåþµØÛìÖîø̵ĵÈýÌÌÐòÓÃÃöÊäÆÄÚø̵ÄÇéöÏÔÊöÀÔÝÍÎñÊÈçϺÔËÐÐRunningºIÍÐÓÁÐReadyQueueºIdiIdj,×èÈûÓÁÐBlockQueueºIdkIdl,======================================================================ø̺ÅÓÅÏÈÊýÒÑÔËÐÐÊäÐèÒªÊäªÊ×èÈûÊä×èÈûÊä×ÌPCATBSPCATBSPCATBSPCATBSPCATBS======================================================================ʵÑéÖÎöºÍËÔÚʵʵÄø̵ÈÖÐÓÐÄÄÐÉÐеÄËãÔõÑùÄÄâÔÚʵʵÄø̵ÈÖÐýÁËËãÑÔñÏÂÒöÔËÐеÄøÌÖÍâÙ×ϵÍÓÃ×öÄÄÐ×ΪÊÃÔø̵ÄÓÅÏÈÊýÉÒÔÉÏÊöÔ,ÔòøÐÐÐÞÄÓÐÊúÃʵÑéÑÊÅźÑÊÔÚµÈÓëËÀËøÄÚÈÝÑÏÖºóøÐÐÄÄâÙ×ϵÍËÄÖÖø̵ÈËãÏÈøÏÈöÌøÌÓÅÏÈßÓÅÏÈÈÓÅÏÈòµÊäÆÂÖתʵÑéÉÒÔÄÄâÈÎÒâÒÖÖÉÒÔ×ÔÒåøÌöÊý×ÔÒåõÊËûÃǵÄÐÃÂÃúÂëº#include"stdafxh"#include<iostream>usingstd::coutusingstd::cinusingstd::cerrenumStatus{running,ready,blocked}enumPolicy{fifo,spf,hpf,rr}typedefclassPCB{ÒåÐÃÂÀàpublic:intid,priority,cputime,alltime,startblock,blocktimeStatusstateclassPCB*nextPCB(){priority=}}PCB,*PCBptr,**PCBppcharxPCBppppÁöÈÖäÁvoidPrint(PCBptrhead){òÓheadΪÍÖÕëµÄÐÃÂÁíÐÅÏPCBptrpcout<<"nÔËÐÐRunningº"for(p=headp>nextp=p>next){if(p>next>state==running){cout<<"ID"<<p>next>idbreak}}cout<<"nÍÐÓÁÐReadyQueueº"for(p=headp>nextp=p>next)if(p>next>state==ready)cout<<"ID"<<p>next>id<<''cout<<"n×èÈûÓÁÐBlockQueueº"for(p=headp>nextp=p>next)if(p>next>state==blocked)cout<<"ID"<<p>next>id<<''cout<<"nn"<<"ø̺ÅÓÅÏÈÊýÒÑÔËÐÐÊäÐèÒªÊäªÊ×èÈûÊä×èÈûÊä×Ìn"for(p=headp>nextp=p>next){cout<<""<<p>next>id<<""<<p>next>priority<<""<<p>next>cputime<<""<<p>next>alltime<<""<<p>next>startblock<<""<<p>next>blocktime<<""switch(p>next>state){caseready:cout<<"ÍÐ"breakcaserunning:cout<<"ÔËÐÐ"breakcaseblocked:cout<<"×èÈû"breakdefault:exit()}cout<<'n'}cout<<"n"<<"ÈÎÒâüÒÔÌÐø"cin>>x}voidDelete(PCBptrhead,PCBptrp){ÉýÒÔheadΪÍÖÕëµÄÐÃÂÁíÖÐpËùÖÏòµÄáµãPCBptrq=headwhile(q>next!=p)q=q>nextq>next=p>nextdeletep}voidInsertSort(PCBppRdy,PCBppRdyEd,Policyalgthm){ÖÓåÈëÅÅÐòif(*(Rdy))ÓÁÐΪÕif(RdyEd!=Rdy){ReadyÓÁÐÖÐÖÒöswitch(algthm){casehpf:if((*(RdyEd))>priority>(*(RdyEd))>priority){PCBpptt*Rdy=*(RdyEd)*(RdyEd)=*(RdyEd)for(tt=RdyEd(*Rdy)>priority>(*tt)>prioritytt)*(tt)=*tt*(tt)=*Rdy}breakcasespf:if((*(RdyEd))>alltime<(*(RdyEd))>alltime){PCBpptt*Rdy=*(RdyEd)*(RdyEd)=*(RdyEd)for(tt=RdyEd(*Rdy)>alltime<(*tt)>alltimett)*(tt)=*tt*(tt)=*Rdy}}}}voidRunToBlk(PCBppRun,PCBppBlkEd){ÒåÔËÐÐÌתΪ×èÈûÌ(*Run)>state=blocked*BlkEd=*RunBlkEd}voidRdyToRun(PCBppRdy,PCBppRun,Policyalgthm){ÒåÍÐÌתΪÔËÐÐÌif(algthm==hpf||algthm==spf){if(*(Rdy)){(*(Rdy))>state=running*Run=*(Rdy)Rdy}}else{if(*Rdy){(*Rdy)>state=running*Run=*RdyRdy}}}voidRunToRdy(PCBppRun,PCBppRdy,PCBppRdyEd,Policyalgthm){ÒåÔËÐÐÌתΪÍÐÌ(*Run)>state=ready*RdyEd=*RunRdyEdif(algthm==hpf||algthm==spf)InsertSort(Rdy,RdyEd,algthm)}intmain(){cout<<"*******************ʵÑéªÊ*******************nnÐèÒª×ööøÌÖÐеÄʵÑé"intnif(!(cin>>n)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}PCBptrListhead,Listp,ListqÁnöListhead=newPCBListp=Listheadfor(inti=i<=ni){Listq=newPCBListp>next=ListqListp=Listq}Listp>next=ÐõÄÓÁÐPolicyalgorithmintnum,numL:cout<<"nÇëÑÔñËãíÊÆÉÆÏíÊÓÐÆíÊÈÐÆíÊÒÒº"if(!(cin>>num)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}algorithm=Policy(num)if(algorithm!=fifoalgorithm!=spfalgorithm!=hpfalgorithm!=rr){cout<<"ÎÞеÄËãÕýÈÇëÖØÐÂÊäÈëºn"gotoL}cout<<"nÏÖÔÚÓÐ"<<n<<"öøÌÊ×ÏÈÎÒÃÇõÊËûÃǵÄÐúnn"Listp=Listhead>nextfor(inti=i<=ni){cout<<"ÇëÊäÈë"<<i<<"ºÅø̵ÄÐún"Listp>id=iif(algorithm==hpf){cout<<"ÓÅÏÈÊýÕûÊýÖµÔóíÃÓÅÏÈÈÔߺ"if(!(cin>>Listp>priority)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}}cout<<"ÒÑÕÓÃÃÐÕÊäÕûÊýÒÔÊäÆΪµÎº"if(!(cin>>Listp>cputime)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}cout<<"ÐèÕÓÃÃÐÕÊäÕûÊýÒÔÊäÆΪµÎº"if(!(cin>>Listp>alltime)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}cout<<"ªÊ×èÈûÊäÕûÊýÒÔÊäÆΪµÎº"if(!(cin>>Listp>startblock)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}cout<<"×èÈûÊäÕûÊýÒÔÊäÆΪµÎº"if(!(cin>>Listp>blocktime)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}L:cout<<"øÌ×ÌíÊÔËÐÐíÊÍÐíÊ×èÈûº"if(!(cin>>num)){cerr<<"íÎóºÊäÈëÕýÈ"exit()}if(num!=num!=num!=){cout<<"×ÌÕýÈÇëÖØÐÂÊäÈëºn"gotoL}Listp>state=Status(num)Listp=Listp>next}PCBppRun=newPCBptr()ÉúÉPCBppReady=newPCBptrfor(inti=i<=i)*(Readyi)=ÔËÐÐPCBppReadyEnd=ReadyÍÐPCBppBlock=newPCBptr×èÈûfor(inti=i<=i)*(Blocki)=PCBppBlockEnd=BlockÓÁÐif(algorithm==hpf||algorithm==spf)ReadyEndÈçûÊÇÈÐÆËãÓÃÖÓåÈëÅÅÐò*ReadyÊÇÉÚøReadyÉΪÓÍfor(Listp=ListheadListp>nextListp=Listp>next){ÑõʵÄøÌÅø×ÔÓÁÐswitch(Listp>next>state){caserunning:*Run=Listp>nextbreakcaseready:{*ReadyEnd=Listp>nextReadyEndif(algorithm==hpf||algorithm==spf)InsertSort(Ready,ReadyEnd,algorithm)break}caseblocked:*BlockEnd=Listp>nextBlockEndbreak}}cout<<"nÏÖÔÚÕâ"<<n<<"öø̪ÊÖÐÐÈÎÒâüÒÔÌÐønn"cin>>xfor(inttime=Listhead>nexttime){ªÊÖÐÐcout<<"nµÚ"<<time<<"öÊäÆáÊøºóº"if(*Run){RunÓÁеÄäif(algorithm==hpf)(*Run)>priority=(*Run)>cputimeif((*Run)>alltime>)(*Run)>alltimeif((*Run)>startblock>)(*Run)>startblock}if(algorithm==hpf){ReadyÓÁеÄäif(*(Ready))for(pp=Readypp!=ReadyEndpp)(*pp)>priority}if(*Block){BlockÓÁеÄäfor(pp=Blockpp!=BlockEndpp)if((*pp)>blocktime>)(*pp)>blocktime}Print(Listhead)if(*Block){pp=Blockwhile(pp!=BlockEnd){ÑÒÑ,×èÈûºÃÁ˵ÄøÌÒƵÍÐÓÁÐif((*pp)>blocktime==){(*pp)>state=ready*ReadyEnd=*ppReadyEndif(algorithm==hpf||algorithm==spf)InsertSort(Ready,ReadyEnd,algorithm)for(PCBppss=ppss!=BlockEndss)*ss=*(ss)BlockEnd}elsepp}}if(*Run){if((*Run)>alltime==){ÈçûÔËÐÐÍêÁËÑÃøÌÏúÄÃÍÐÓ͵ÄøÌÀÔËÐÐDelete(Listhead,*Run)RdyToRun(Ready,Run,algorithm)}else{ÃÔËÐÐÍêif((*Run)>startblock==){ÈçûÃ×èÈûÁËÔòÅÈë×èÈûÓÁÐÄÃÍÐÓ͵ÄøÌÀÔËÐÐRunToBlk(Run,BlockEnd)RdyToRun(Ready,Run,algorithm)}else{ÈçûÃ×èÈûif(algorithm==hpf){ÔÚÈÐÆËãÏÂÈÏÏÖÔÚÔËÐеÄø̵ÄÓÅÏÈȺÍ*(Ready)µÄÓÅÏÈȵÄóÐif(*(Ready))if((*Run)>priority<(*(Ready))>priority){ÏÂÌÁË(*Run)>state=ready*ReadyEnd=*RunReadyEndInsertSort(Ready,ReadyEnd,algorithm)if(*(Ready)){(*(Ready))>state=running*Run=*(Ready)Ready}}}if(algorithm==rr){ÔÚòòËãÏÂÍÓÈëÍÐÓÎ(*Run)>state=ready*ReadyEnd=*RunReadyEndif(*Ready){(*Ready)>state=running*Run=*ReadyReady}}}}}elseRdyToRun(Ready,Run,algorithm)}return}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/16

操作系统进程调度模拟实验

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利