您好,欢迎访问三七文档
1课程名称操作系统实验序号实验一、二进程调度算法实验项目实验地点综B504实验学时4实验类型设计性指导教师刘劲武实验员专业____计算机科学与技术(师范)__班级16计本学号2016324123姓名刘伯相2018年5月23日2成绩:教师评语实验一进程调度I实验时数:4开设要求:必做实验性质:设计性每组人数:1实验目的与实验要求:用高级语言实现简单的进程调度,通过本实验加深对进程调度的理解。设计PCB结构,建立进程就绪队列,编制先来先服务调度算法进程调度算法主要仪器设备:PC机实验二进程调度II实验时数:4开设要求:必做实验性质:设计性每组人数:1实验目的与实验要求:用高级语言实现简单的进程调度,通过本实验加深对进程调度的理解。设计PCB结构,建立进程就绪队列,编制高响应比优先调度算法进程调度算法主要仪器设备:PC机代码如下:#includestdio.h#includestdlib.h#includealgorithmusingnamespacestd;typedefstructPCB{charproduce[10];intarrivetime;3intbegintime;intfinishtime;intruntime;intrighttime;intservicetime;intwaittime;floatright;floatquan;}PCB;//按照进程到达时间排序intcmp(PCBa,PCBb){if(a.arrivetimeb.arrivetime)return1;elsereturn0;}//按照进程优先权排序intcmp1(PCBa,PCBb){if(a.quanb.quan)return1;elsereturn0;}//先进先出算法voidFCFS(PCBwork[],intn){inti;work[0].begintime=work[0].arrivetime;for(i=0;in;i++){work[i].finishtime=work[i].begintime+work[i].runtime;work[i].righttime=work[i].finishtime-work[i].arrivetime;work[i].right=work[i].righttime*1.0/work[i].runtime;work[i+1].begintime=work[i].finishtime;}printf(-------------------------------FCFS先进先出算法------------------------------\n);4printf(进程名到达时间运行时间开始时间结束时间周转时间周转系数\n);for(i=0;in;i++){printf(%s\t%d\t\t%d\t%d\t%d\t\t%d\t,work[i].produce,work[i].arrivetime,work[i].runtime,work[i].begintime,work[i].finishtime,work[i].righttime,work[i].righttime);printf(%.2f\n,work[i].right);}}//高响应比算法voidHRR(PCBwork[],intn){inti;work[0].begintime=work[0].arrivetime;for(i=0;in;i++){work[i].finishtime=work[i].begintime+work[i].runtime;for(intj=i+1;jn;j++)if(work[j].arrivetimework[i].finishtime)work[j].quan=(work[i].finishtime-work[j].arrivetime+work[j].runtime)/(work[j].runtime*1.0);//计算优先权,确定下一个要运行的进程sort(work+i+1,work+n,cmp1);//根据进程的优先权排序,运行优先权大的进程work[i].righttime=work[i].finishtime-work[i].arrivetime;work[i].right=work[i].righttime*1.0/work[i].runtime;work[i+1].begintime=work[i].finishtime;}printf(-------------------------------HRR算法------------------------------\n);printf(进程名到达时间运行时间开始时间结束时间周转时间周转系数\n);for(i=0;in;i++){printf(%s\t%d\t\t%d\t%d\t%d\t\t%d\t,work[i].produce,work[i].arrivetime,work[i].runtime,work[i].begintime,work[i].finishtime,work[i].righttime,work[i].righttime);5printf(%.2f\n,work[i].right);}}voidmain(){PCBwork[6];inti,n;printf(请输入进程个数:\n);scanf(%d,&n);getchar();for(i=0;in;i++){printf(请分别输入第%d个进程的进程名字\t到达时间\t运行时间\n,i+1);scanf(%s%d%d,&work[i].produce,&work[i].arrivetime,&work[i].runtime);}sort(work,work+n,cmp);printf(按进程的到达时间排序\n);printf(进程名\t到达时间运行时间\n);for(i=0;in;i++)printf(%s\t%d\t\t%d\n,work[i].produce,work[i].arrivetime,work[i].runtime);FCFS(work,n);HRR(work,n);}五、测试/调试及实验结果分析6六、实验结论与体会2018年5月23日
本文标题:操作系统先来先服务
链接地址:https://www.777doc.com/doc-4966015 .html