时间片轮转调度算法Word文档格式.docx

上传人:b****6 文档编号:19127490 上传时间:2023-01-04 格式:DOCX 页数:11 大小:218.54KB
下载 相关 举报
时间片轮转调度算法Word文档格式.docx_第1页
第1页 / 共11页
时间片轮转调度算法Word文档格式.docx_第2页
第2页 / 共11页
时间片轮转调度算法Word文档格式.docx_第3页
第3页 / 共11页
时间片轮转调度算法Word文档格式.docx_第4页
第4页 / 共11页
时间片轮转调度算法Word文档格式.docx_第5页
第5页 / 共11页
点击查看更多>>
下载资源
资源描述

时间片轮转调度算法Word文档格式.docx

《时间片轮转调度算法Word文档格式.docx》由会员分享,可在线阅读,更多相关《时间片轮转调度算法Word文档格式.docx(11页珍藏版)》请在冰豆网上搜索。

时间片轮转调度算法Word文档格式.docx

//结束运行时间

inttotalTime。

//周转时间

floatweightTotalTime。

//带权周转时间

}。

structQueueNode

intID。

//进程ID

structQueueNode*next。

//队列中下一个进程指针

structLinkQueue

QueueNode*head。

//队首

voidFcfs(LinkQueue&

Q,int&

totalTimeSum,int&

weightTotalTimeSum,PCBNode*ProcessTable>

RTCrpUDGiT

boolRR_Run(LinkQueue&

Q,QueueNode*q,QueueNode*p,constintRound,int&

currentTime,PCBNode*ProcessTable>

5PCzVD7HxA

//分配时间片给q所指进程,p为刚退出的进程

voidRoundRobin(LinkQueue&

Q,constintRound,int&

jLBHrnAILg

//时间片轮转调度,调用RR_Run(>

时间片大小设为Round

voidInitialQueue(LinkQueue&

Q,PCBNode*ProcessTable,constintprocessnum>

xHAQX74J0X

//初始化就绪队列

voidInput(PCBNode*ProcessTable,constintprocessnum>

LDAYtRyKfE

//从input.txt文件输入数据

intmain(>

LinkQueueQ。

//就绪队列

Q.head=NULL。

constintprocessnum=16。

//进程数

constintRound=1。

//时间片大小

inttotalTimeSum=0。

intWeightTotalTimeSum=0。

//带权周转时间

PCBNode*ProcessTable=newPCBNode[processnum]。

//进程表Zzz6ZB2Ltk

Input(ProcessTable,processnum>

InitialQueue(Q,ProcessTable,processnum>

RoundRobin(Q,Round,totalTimeSum,WeightTotalTimeSum,ProcessTable>

dvzfvkwMI1

cout<

<

"

时间片轮调度的平均周转时间为:

totalTimeSum/processnum<

endl。

rqyn14ZNXI

时间片轮调度的平均带权周转时间为:

WeightTotalTimeSum/processnum<

EmxvxOtOco

Fcfs(Q,totalTimeSum,WeightTotalTimeSum,ProcessTable>

SixE2yXPq5

先来先服务的平均周转时间为:

6ewMyirQFL

先来先服务的平均带权周转时间为:

kavU42VRUs

delete[]ProcessTable。

return0。

}

y6v3ALoS89

totalTimeSum=0。

//总的周转时间

weightTotalTimeSum=0。

//平均周转时间

intcurrentTime=0。

//当前时间

QueueNode*p。

QueueNode*q。

QueueNode*r。

boolfinish=false。

//调用RR_Run(>

后,该进程是否已经做完退出M2ub6vSTnP

p=Q.head。

q=p->

next。

while(q!

=NULL>

//从队首开始依次分配时间片

{

do

**********************"

在时间片"

(currentTime+1>

/Round<

内,活动进程为:

q->

ID<

0YujCfmUCw

进程"

现在需要的时间片为:

ProcessTable[q->

ID].remainTime<

eUts8ZQVRd

finish=RR_Run(Q,q,p,Round,currentTime,ProcessTable>

//分配时间片给q进程sQsAEJkW5T

if(!

finish>

//若是进程在本时间片内做完,则跳出do…while循环

if(q->

next==NULL>

r=Q.head->

}

else

r=q->

else//否则计算周转时间和带权周转时间

totalTimeSum+=ProcessTable[q->

ID].totalTime。

GMsIasNXkA

weightTotalTimeSum+=ProcessTable[q->

ID].weightTotalTime。

TIrRGchYzg

deleteq。

//从队列中删除q进程

q=p。

}while(!

finish&

&

(ProcessTable[r->

ID].arriveTime>

currentTime+Round>

>

7EqZcWLZNX

//下一个进程很晚才来,则继续给当前进程分配时间片

p=q。

q=q->

if(q==NULL&

Q.head->

next!

=NULL>

deleteQ.head。

lzq7IGf02E

if(ProcessTable[q->

=Round>

//在此时间片内能够做完,之后退出进程调度zvpgeqJ1hk

ProcessTable[q->

ID].finishTime=currentTime+ProcessTable[q->

ID].remainTime。

NrpoJac3v1

ID].totalTime+=ProcessTable[q->

1nowfTG4KI

ID].weightTotalTime=ProcessTable[q->

ID].totalTime/ProcessTable[q->

ID].reqTime。

fjnFLDa5Zo

currentTime=ProcessTable[q->

ID].finishTime。

p->

next=q->

完成!

returntrue。

else//此时间片内做不完

ID].remainTime=ProcessTable[q->

ID].remainTime-Round。

tfnNhnE6e5

ID].totalTime+=Round。

currentTime+=Round。

returnfalse。

}

HbmVN777sL

p=Q.head->

if(p!

=NULL>

ProcessTable[p->

ID].startTime=ProcessTable[p->

ID].arriveTime。

V7l4jRB8Hs

ID].finishTime=ProcessTable[p->

ID].arriveTime+ProcessTable[p->

83lcPA59W9

for(q=p->

q!

=NULL。

q=q->

next>

ID].arriveTime<

ID].finishTime>

mZkklkzaaP

AVktR43bpw

ID].finishTime+ProcessTable[q->

ORjBnOwcEd

else//下个进程到达时间较晚

ID].startTime=ProcessTable[q->

2MiJTy0dTT

ID].finishTime=ProcessTable[q->

ID].arriveTime+ProcessTable[q->

gIiSpiue7A

for(q=Q.head->

ID].totalTime=ProcessTable[q->

ID].finishTime-ProcessTable[q->

uEh0U1Yfmh

IAg9qLsgBX

WwghWvVhPE

asfpsfpi4k

intt=0。

*********************"

while(t<

ID].finishTime>

时刻"

t<

:

进程"

活动"

ooeyYZTjj1

t++。

next!

结束活动,开始下一个进程."

BkeGuInkxI

的周转时间为:

ID].totalTime<

PgdO0sRlMo

的带权周转时间为:

ID].weightTotalTime<

endl<

3cdXwckm15

结束活动."

h8c52WOngM

v4bdyGious

J0bm4qMpJ9

所有进程结束活动."

deletep。

Q,PCBNode*ProcessTable,constintprocessnum>

XVauA9grYP

//初始化

for(inti=0。

i<

processnum。

i++>

ProcessTable[i].processID=i。

ProcessTable[i].reqTime=ProcessTable[i].remainTime。

bR9C6TJscw

ProcessTable[i].finishTime=0。

ProcessTable[i].startTime=0。

ProcessTable[i].status=WAIT。

ProcessTable[i].totalTime=0。

ProcessTable[i].weightTotalTime=0。

Q.head=newQueueNode。

next=NULL。

QueueNode*p。

QueueNode*q。

for(i=0。

p=newQueueNode。

ID=i。

if(i==0>

next=p。

q->

pN9LBDdtrd

FILE*fp。

//读入线程的相关内容

if((fp=fopen("

input.txt"

"

r"

==NULL>

cannotopenfile!

exit(0>

for(inti=0。

fscanf(fp,"

%d%d%d"

&

ProcessTable[i].arriveTime,&

ProcessTable[i].remainTime,&

ProcessTable[i].priorityNum>

DJ8T7nHuGT

fclose(fp>

建议输入数据:

input.txt

040

1351

2102

353

694

7215

9356

11237

12428

1319

14710

20511

23312

242213

253114

26115

申明:

所有资料为本人收集整理,仅限个人学习使用,勿做商业用途。

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

当前位置:首页 > 自然科学

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

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