关闭

关闭

关闭

封号提示

内容

首页 使用动态优先权的进程调度算法的模拟.doc

使用动态优先权的进程调度算法的模拟.doc

使用动态优先权的进程调度算法的模拟.doc

上传者: 爱有多深伤就有多深 2018-01-13 评分 0 0 0 0 0 0 暂无简介 简介 举报

简介:本文档为《使用动态优先权的进程调度算法的模拟doc》,可适用于IT/计算机领域,主题内容包含使用动态优先权的进程调度算法的模拟实验四使用动态优先权的进程调度算法的模拟、实验目的通过动态优先权算法的模拟加深对进程概念和进程调度过程的理解。、实符等。

使用动态优先权的进程调度算法的模拟实验四使用动态优先权的进程调度算法的模拟、实验目的通过动态优先权算法的模拟加深对进程概念和进程调度过程的理解。、实验内容()用C语言来实现对N个进程采用动态优先算法的进程调度()每个用来标识进程的进程控制块PCB用结构来描述包括以下字段:,进程标识符id,进程优先数priority并规定优先数越大的进程其优先权越高,进程已占用的CPU时间cputime,进程还需占用的CPU时间alltime当进程运行完毕时alltime变为,进程的阻塞时间startblock表示当进程再运行startblock个时间片后进程将进入阻塞状态,进程被阻塞的时间blocktime表示已阻塞的进程再等待blocktime个时间片后将转换成就绪态,进程状态state,队列指针next用来将PCB排成队列()优先数改变的原则:,进程在就绪队列中呆一个时间片优先数增加,进程每运行一个时间片优先数减。()假设在调度前系统中有个进程它们的初始状态如下:IDPRIORITYCPUTIMEALLTIMESTARTBLOCKBLOCKTIMESTATEREADYREADYREADYREADYREADY()为了清楚地观察诸进程的调度过程程序应将每个时间片内的进程的情况显示出来参照的具体格式如下:RUNNINGPROG:iREADYQUEUE:>id>idBLOCKQUEUE:>id>id==================================IDPRIORITYPPPPPCPUTIMECCCCCALLTIMEAAAAASTARTBLOCKTTTTTBLOCKTIMEBBBBBSTATESSSSS程序:、程序示例:A使用动态优先权的进程调度算法的模拟byYanQiwei#include<stdioh>#defineNvoidinit()voidprint()intgetRunning()voidsort()intrun(inttime)enumSTATE{Ready,Run,Block,RunOut}structPROCESS{intIDintPriorityintCputimeintAlltimeintStartblockintBlocktimeenumSTATEState}ProcessNintREADYNintBLOCKNintRUNOUTNintmain(){intTime=init()printf("Time:dn",Time)sort()print()while(){Timegetchar()printf("Time:dn",Time)if(run(Time))breaksort()}print(Time)return}voidinit(){intiprintf("Inputpropertiesofdprocess(PRIORITY,ALLTIME,STARTBLOCK,BLOCKTIME):n",N)for(i=i<Ni){READYi=BLOCKi=RUNOUTi=RUNOUTi=ProcessiID=iProcessiCputime=ProcessiState=Ready*printf("Numberd:",i)scanf("d,d,d,d",ProcessiPriority,ProcessiAlltime,ProcessiStartblock,ProcessiBlocktime)*ProcessiStartblock=ProcessiBlocktime=}ProcessPriority=ProcessAlltime=ProcessStartblock=ProcessBlocktime=ProcessPriority=ProcessAlltime=ProcessPriority=ProcessAlltime=ProcessPriority=ProcessAlltime=ProcessPriority=ProcessAlltime=}voidprint(){intiif(getRunning()>=)printf("tRUNNINGPROG:dn",getRunning())printf("tREADYQUEUE:")for(i=i<Ni){if(READYi>=)printf(">d",ProcessREADYiID)else{break}}printf("ntBLOCKQUEUE:")for(i=i<Ni){if(BLOCKi>=)printf(">d",ProcessBLOCKiID)else{break}}printf("n=====================================================n")printf("IDt")for(i=i<Ni){printf("td",ProcessiID)}printf("nPRIORITY")for(i=i<Ni){printf("td",ProcessiPriority)}printf("nCPUTIMEt")for(i=i<Ni){printf("td",ProcessiCputime)}printf("nALLTIMEt")for(i=i<Ni){printf("td",ProcessiAlltime)}printf("nSTARTBLOCK")for(i=i<Ni){printf("td",ProcessiStartblock)}printf("nBLOCKTIME")for(i=i<Ni){printf("td",ProcessiBlocktime)}printf("nSTATEt")for(i=i<Ni){switch(ProcessiState){case:printf("tReady")breakcase:printf("tRun")if(ProcessiAlltime==){ProcessiState=RunOut}elseProcessiState=Readybreakcase:printf("tBlock")breakcase:printf("tRunOut")break}}printf("n")printf("tRUNOUTLIST:")for(i=i<Ni){if(RUNOUTi>=)printf(">d(d)",ProcessRUNOUTiID,RUNOUTi)else{printf("n")break}}printf("n")}intgetRunning(){intifor(i=i<Ni){if(ProcessiState==Run)returni}for(i=i<Ni){if(ProcessiStartblock==)returni}return}voidsort(){inti,j,kfor(i=i<Ni){READYi=BLOCKi=}for(i=i<Ni){if(ProcessiState==Ready||ProcessiState==Run){ProcessiState=Readyif(ProcessiAlltime==)continuefor(j=j<Nj){if(READYj<){READYj=ibreak}elseif(ProcessiPriority<=ProcessREADYjPriority){continue}else{for(k=Nk>jk){READYk=READYk}READYj=ibreak}}}elseif(ProcessiState==Block){for(j=j<Nj){if(BLOCKj<){BLOCKj=ibreak}elseif(ProcessiBlocktime>=ProcessBLOCKjBlocktime){continue}else{for(k=Nk>jk){BLOCKk=BLOCKk}BLOCKj=ibreak}}}}}intrun(inttime){inti,runNumrunNum=READYif(runNum<BLOCK<){printf("EveryprocessisOVER!n")return}else{if(runNum>=){ProcessrunNumPriority=ProcessrunNumAlltime=ProcessrunNumCputime=ProcessrunNumState=Runfor(i=i<Ni){if(i!=runNum){if(ProcessiState==Ready){ProcessiPriority=}elseif(ProcessiState==Block){ProcessiBlocktime=if(ProcessiBlocktime==){ProcessiState=Ready}}}}print()if(ProcessrunNumAlltime==){ProcessrunNumState=RunOutfor(i=i<Ni){if(RUNOUTi<){RUNOUTi=runNumRUNOUTi=timebreak}}}elseif(ProcessrunNumStartblock>=){ProcessrunNumStartblock=if(ProcessrunNumStartblock==){ProcessrunNumState=BlockProcessrunNumStartblock=}}}elseif(BLOCK>=){for(i=i<Ni){if(ProcessiState==Block){ProcessiStartblock=ProcessiBlocktime=if(ProcessiBlocktime==){ProcessiState=Ready}}}print()}}sort()print()return}、思考题()在实际的调度中除了按调度算法选择下一个执行的进程外还应处理哪些工作,运行结果

用户评论(0)

0/200

精彩专题

上传我的资料

每篇奖励 +2积分

资料评价:

/18
0下载券 下载 加入VIP, 送下载券

意见
反馈

立即扫码关注

爱问共享资料微信公众号

返回
顶部