实验三 进程调度(Java)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实验三进程调度(一)教学要求了解单处理器情况下进程调度的过程。(二)知识点提示各种进程调度算法。(三)教学内容运行下面的程序,回答问题。publicclassProgressData{publicintarrived;//进程到达时间publicintserver;//进程服务时间publicintfinished;//进程完成时间publicintworking;//进程周转时间publicfloatpowerWorking;//带权周转时间publicProgressData(){};publicProgressData(intarr,intser){arrived=arr;server=ser;}publicStringtoString(){returnarrived+\t+server+\t+finished+\t+working+\t+String.format(%.2f,powerWorking);}}publicclassProgressMain{//先来先服务publicstaticvoidFCFS(ProgressDataa[]){intpreFinished=0;ProgressDataa1[]=a;floattotal_powerWorking=0;for(inti=0;ia1.length;i++){a1[i].finished=0;a1[i].working=0;a1[i].powerWorking=0;}for(inti=0;ia1.length;i++){a1[i].finished=preFinished+a1[i].server;a1[i].working=a1[i].finished-a1[i].arrived;a1[i].powerWorking=a1[i].working/(float)a1[i].server;preFinished=a1[i].finished;}System.out.println(先来先服务算法:);System.out.println(到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间);for(intj=0;ja1.length;j++){System.out.println(a1[j]);total_powerWorking+=a1[j].powerWorking;}System.out.println(平均带权周转时间:+String.format(%.2f,(total_powerWorking/5)));}//短进程优先publicstaticvoidSJF(ProgressDataa[]){intpreFinished=0;intnum=1,min=4444;ProgressDataa1[]=a;floattotal_powerWorking=0;for(inti=0;ia1.length;i++){a1[i].finished=0;a1[i].working=0;a1[i].powerWorking=0;}for(inti=0;ia1.length;i++){min=4444;for(intj=0;ja1.length;j++){if(a1[j].servermin&&a1[j].finished==0&&a1[j].arrived=preFinished){min=a1[j].server;num=j;}}a1[num].finished=preFinished+a1[num].server;a1[num].working=a1[num].finished-a1[num].arrived;a1[num].powerWorking=a1[num].working/(float)a1[num].server;preFinished=a1[num].finished;}System.out.println(短进程优先算法:);System.out.println(到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间);total_powerWorking=0;for(intj=0;ja1.length;j++){total_powerWorking+=a1[j].powerWorking;System.out.println(a1[j]);}System.out.println(平均带权周转时间:+String.format(%.2f,(total_powerWorking/5)));}//响应比高者优先publicstaticvoidHRRN(ProgressDataa[]){intpreFinished=0;intnum=0;floatpriority=1000;floattotal_powerWorking=0;ProgressDataa1[]=a;for(inti=0;ia1.length;i++){a1[i].finished=0;a1[i].working=0;a1[i].powerWorking=0;}for(inti=0;ia1.length;i++){priority=-1000;for(intj=0;ja1.length;j++){intsub=((preFinished-a1[j].arrived)+a1[j].server)/a1[j].server;if(subpriority&&a1[j].finished==0&&a1[j].arrived=preFinished){priority=sub;num=j;}}a1[num].finished=preFinished+a1[num].server;a1[num].working=a1[num].finished-a1[num].arrived;a1[num].powerWorking=a1[num].working/(float)a1[num].server;preFinished=a1[num].finished;}System.out.println(高响应比优先算法:);System.out.println(到达时间\t服务时间\t完成时间\t周转时间\t带权周转时间);total_powerWorking=0;for(intj=0;ja1.length;j++){System.out.println(a1[j]);total_powerWorking+=a1[j].powerWorking;}System.out.println(平均带权周转时间:+String.format(%.2f,(total_powerWorking/5)));}(1)写出程序的运行结果。(2)比较三种调度算法的优劣。(3)若进程调度按静态优先级调度:5个进程的优先级分别为:6,3,7,9,4(值越小,表示优先级越高),请写出程序,模拟调度算法的执行并写出运行结果。(四)思考题1、简要描述三种类型的处理机调度。2、抢占式和非抢占式调度有什么区别?3、周转时间和响应时间有什么区别?publicstaticvoidmain(String[]args){ProgressDatap[]=newProgressData[5];p[0]=newProgressData(0,4);p[1]=newProgressData(1,3);p[2]=newProgressData(2,5);p[3]=newProgressData(3,2);p[4]=newProgressData(4,4);FCFS(p);SJF(p);HRRN(p);}}

1 / 4
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功