时间片轮转法完成进程调度【实验目的】(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("请输入时间片 pl 需要运行的时间:");scanf("%d",&time);pcbl.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();//初始化12524■■■■■-■■Bl.可.-_T7•_T7=.42"-E?l-l-I」一 I」 - - I」二I」 -- c^IIIIII仃 M11f害零專專星 E"|12345er暑宾・LI肘BTrffitBd-Ik芸人iAixiAiAi请请请请主plSTtimerplid'ocessesplrunnLngfSTtiinerrpiprintf("thisisthebeginstate:\n");printf2();〃显示初始状态operation();〃运行}【结果截图】■■■■■\ProgzaMFlies\BicrosoftVisualStudio\ByProjects\Debug.exe