实验短作业优先SJF进程调度算法模拟一、实验目的模拟单处理器系统的进程调度,采用短作业优先的进程调度算法作为进程设计算法,以加深对进程的概念及进程调度算法的理解.二、实验内容如进程信息如下:structPCBpcb[N]={{AAA,0,4},{BBB,1,3},{CCC,2,5},{DDD,15,2},{EEE,4,4}};进程名到达时间运行时间完成时间周转时间A0444B1376C251614D152183E44117#includestdio.h#includestring.h#includestdlib.h#includeconio.h#defineN5structPCB{charname[8];intarrive_time;intrun_time;intfinish_time;intzhouzhuan_time;floatdaiquan_time;};floatpinjun_zhouzhuan_time;floatpinjun_daiquan_time;structPCBpcb[N]={{DDD,3,2},{AAA,0,4},{BBB,1,3},{CCC,2,5},{EEE,4,4}};voidoutput(){printf(进程名到达时间运行时间完成时间周转时间带权周转时间\n);for(inti=0;iN;i++){printf(%s%d%d%d%d%f\n,pcb[i].name,pcb[i].arrive_time,pcb[i].run_time,pcb[i].finish_time,pcb[i].zhouzhuan_time,pcb[i].daiquan_time);}}voidsortPCB(){structPCBtemp;inti,j;for(i=0;iN-1;i++)for(j=i+1;jN;j++)if(pcb[i].arrive_timepcb[j].arrive_time){temp=pcb[j];pcb[j]=pcb[i];pcb[i]=temp;}}voidmain(){inti;printf(进程初始状态\n);output();printf(进程按到达时间排序后的状态\n);sortPCB();output();for(i=0;iN;i++){//下面计算本进程的完成时间if(i==0)pcb[i].finish_time=pcb[i].run_time+pcb[i].arrive_time;elseif(pcb[i].arrive_timepcb[i-1].finish_time)pcb[i].finish_time=pcb[i-1].finish_time+pcb[i].run_time;elsepcb[i].finish_time=pcb[i].arrive_time+pcb[i].run_time;//下面计算本进程的周转时间pcb[i].zhouzhuan_time=pcb[i].finish_time-pcb[i].arrive_time;//下面计算本进程的带权周转时间pcb[i].daiquan_time=(float)pcb[i].zhouzhuan_time/pcb[i].run_time;}inttotal_zhouzhuan_time=0;floattotal_daiquan_time=0;for(i=0;iN;i++){total_zhouzhuan_time+=pcb[i].zhouzhuan_time;total_daiquan_time+=pcb[i].daiquan_time;}pinjun_zhouzhuan_time=(float)total_zhouzhuan_time/N;pinjun_daiquan_time=total_daiquan_time/N;printf(计算后的结果输出\n);output();printf(平均周转时间为:%f\n,pinjun_zhouzhuan_time);printf(平均带权周转时间为:%f\n,pinjun_daiquan_time);}