OS时间片轮转调度算法Word文档格式.docx
- 文档编号:22240014
- 上传时间:2023-02-03
- 格式:DOCX
- 页数:7
- 大小:15.81KB
OS时间片轮转调度算法Word文档格式.docx
《OS时间片轮转调度算法Word文档格式.docx》由会员分享,可在线阅读,更多相关《OS时间片轮转调度算法Word文档格式.docx(7页珍藏版)》请在冰豆网上搜索。
//进程运行CPU时间
intpieceOftime;
//轮转时间片
stringprocname;
//进程名
stringstate;
//进程状态
intneedOftime;
//还需要时间
intCounter;
PCB*next;
};
PCB*run=NULL;
PCB*ready=NULL;
PCB*finish=NULL;
PCB*tial=ready;
voidDtime(intt);
voidPrinft(inta)
if(a==1)
coutvv"
进程名称"
vv"
\\t"
优先数"
还需要时间"
已运行时间"
<
"
状态:
endl;
else
已运行时间"
计数器"
时间片"
状态"
vvendl;
voidPrinft(intb,PCB*p)
if(b==1)
cout<
p->
procname<
\\t\\t"
pri<
needOftime<
runtime<
state<
runtime<
\\t\\t
Counter<
pieceOftime<
voiddisplay(intc)
PCB*p;
if(run!
=NULL)/*如果运行指针不空*/
Prinft(c,run);
/*输出当前正在运行的PCB*/
//Dtime
(2);
p=ready;
/*输出就绪队列PCB*/
while(p!
=NULL)
Prinft(c,p);
p=p->
next;
p=finish;
/*输出完成队列的PCB*/
voidinsert(PCB*p)//插入就绪队列按Pri大小
PCB*S1,*S2;
if(ready==NULL)
next=NULL;
ready=p;
S1=ready;
S2=S1;
while(S1!
if(S1->
pri>
=p->
pri)
S1=S1->
break;
if(S2->
S2->
next=p;
next=S1;
next=ready;
boolCTProcessOfPri()
PCB*Node;
输入创建进程的数目:
cin>
>
n;
for(intj=0;
j<
j++)
Node=newPCB;
if(Node==NULL)
returnfalse;
输入进程的名称,进程需CPU时间:
cin>
Node->
procname>
needOftime;
runtime=0;
state二"
就绪"
;
pri=Node->
进程"
vvNode->
procnameW创建完毕!
insert(Node);
returntrue;
voidpriority(inti)
run=ready;
ready=ready->
run->
运行”;
Prinft(i);
while(run!
=NULL)/*当运行队列不空时,有进程正在运行*/
runtime=run->
runtime+1;
needOftime=run->
needOftime-1;
pri=run->
pri-1;
/*每运行一次优先数降低1个单位*/
if(run->
needOftime==0)/*如所需时间为0将其插入完成队列*/
完成"
next=finish;
finish=run;
run二NULL;
/*运行队列头指针为空*/
if(ready!
二NULL)/*如就绪队列不空*/
elseif((ready!
=NULL)&
&
(run->
ready->
pri))
insert(run);
运行"
display(i);
/*输出进程PCB信息*/
voidqueue(PCB*p)
tial=p;
tial->
boolCTProcessOfRuntime()
intm;
输入时间片:
m;
jvn;
Counter=0;
pieceOftime=m;
'
创建完毕!
queue(Node);
voidRuntime(intc)
Prinft(c);
Counter=run->
Counter+1;
needOftime==0)
完成”;
run=NULL;
elseif(run->
Counter==run->
pieceOftime)
就绪”;
queue(run);
display(c);
intmain()
inti;
*******************************************"
*1优先数调度算法2循环时间片轮转算法*"
***************0退出*******************"
i;
switch(i)
case1:
CTProcessOfPri();
priority(i);
case2:
CTProcessOfRuntime();
Runtime(i);
default:
return0;
voidDtime(intt)
time_tcurrent_time;
time_tstart_time;
time(&
start_time);
do
current_time);
}while((current_time-start_time)<
t);
3)编译并运行,其结果为:
4)输入相应的操作,结果为:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- OS 时间 轮转 调度 算法