时间片轮法完成进程调度操作系统实验报告.docx

上传人:b****8 文档编号:10051362 上传时间:2023-02-08 格式:DOCX 页数:9 大小:123.42KB
下载 相关 举报
时间片轮法完成进程调度操作系统实验报告.docx_第1页
第1页 / 共9页
时间片轮法完成进程调度操作系统实验报告.docx_第2页
第2页 / 共9页
时间片轮法完成进程调度操作系统实验报告.docx_第3页
第3页 / 共9页
时间片轮法完成进程调度操作系统实验报告.docx_第4页
第4页 / 共9页
时间片轮法完成进程调度操作系统实验报告.docx_第5页
第5页 / 共9页
点击查看更多>>
下载资源
资源描述

时间片轮法完成进程调度操作系统实验报告.docx

《时间片轮法完成进程调度操作系统实验报告.docx》由会员分享,可在线阅读,更多相关《时间片轮法完成进程调度操作系统实验报告.docx(9页珍藏版)》请在冰豆网上搜索。

时间片轮法完成进程调度操作系统实验报告.docx

时间片轮法完成进程调度操作系统实验报告

时间片轮转法完成进程调度

【实验目的】

(1)加深对进程的理解

(2)理解进程控制块的结构

(3)理解进程运行的并发性

(4)掌握时间片轮转法进程调度算法

【实验内容】

(1)建立进程控制块

(2)设计三个链队列,分别表示运行队列、就绪队列和完成队列

(3)用户输入进程标识符以及进程所需的时间,申请空间存放进程PCB信息。

(4)每一个时间片结束输出各进程的进程号,CPU时间(即已经占用的CPU时间),所需时间(即还需要的CPU时间),以及状态(即用W表示等待,R表示运行,F表示完成)

【程序代码】

#include"stdio.h"

#include"stdlib.h"

structPCB

{

intpid;//进程标识符

intrr;//已运行时间

inttime;//进程要求运行时间

charsta;//进程的状态

structPCB*next;//链接指针

};

structPCBpcb1,pcb2,pcb3,pcb4,pcb5,*tail,*head,*rp;

init()

{

inti,time;

pcb1.pid=1;

pcb2.pid=2;

pcb3.pid=3;

pcb4.pid=4;

pcb5.pid=5;

pcb1.rr=pcb2.rr=pcb3.rr=pcb4.rr=pcb5.rr=0;

pcb1.sta=pcb2.sta=pcb3.sta=pcb4.sta=pcb5.sta='w';

printf("请输入时间片p1需要运行的时间:

");

scanf("%d",&time);

pcb1.time=time;

printf("请输入时间片p2需要运行的时间:

");

scanf("%d",&time);

pcb2.time=time;

printf("请输入时间片p3需要运行的时间:

");

scanf("%d",&time);

pcb3.time=time;

printf("请输入时间片p4需要运行的时间:

");

scanf("%d",&time);

pcb4.time=time;

printf("请输入时间片p5需要运行的时间:

");

scanf("%d",&time);

pcb5.time=time;

pcb1.next=&pcb2;

pcb2.next=&pcb3;

pcb3.next=&pcb4;

pcb4.next=&pcb5;

pcb5.next=&pcb1;

head=&pcb1;

tail=&pcb5;

}

voidprintf1()

{

printf("+---------------|---------------|---------------|---------------+\n");

printf("|\tpid\t|\trr\t|\ttime\t|\tSTA\t|\n");

printf("|---------------|---------------|---------------|---------------|\n");

}

printf2()

{

printf("processesp%drunning\n",head->pid);

printf1();

printf("|\t%d\t|\t%d\t|\t%d\t|\t%c\t|\n",head->pid,head->rr,head->time,head->sta);

printf("|---------------|---------------|---------------|---------------|\n");

rp=head;

while(rp!

=tail)

{

rp=rp->next;

printf("|\t%d\t|\t%d\t|\t%d\t|\t%c\t|\n",rp->pid,rp->rr,rp->time,rp->sta);

printf("|---------------|---------------|---------------|---------------|\n");

}

}

operation()

{

intflag=1;

while(flag<=5)

{

head->rr++;

if((head->rr==head->time)||(head->time==0))

{

tail->sta='w';

head->sta='f';

printf2();

head=head->next;

tail->next=head;

flag++;

}

else

{

tail->sta='w';

head->sta='r';

printf2();

tail=head;

head=head->next;

}

}

}

voidmain()

{

init();//初始化

printf("thisisthebeginstate:

\n");

printf2();//显示初始状态

operation();//运行

}

【结果截图】

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

当前位置:首页 > 幼儿教育 > 幼儿读物

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

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