版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实用文档实验概述:【实验目的及要求】理解并掌握处理机调度算法【实验原理】基于先来先服务调度和最短作业优先调度算法思想用C语言编程实现【实验环境】(使用的软件)Visual C+6.0实验内容:本实验模拟在单处理机情况下处理机调度,用C语言编程实现先来先服务和最短作业优先调度算法。【实验方案设计】FCFS流程图:向驱堤LLrs实用文档技至U法IM F nJ从刁 的J大X4 UtfTilt辛 了14=&迄出羽 亍*d !EUVjiaWFTd-r JW 各缨*iA 些堆 坦歧整行ITJ I 1MI E遂彼问腴:;:;2L 甲 2 并如时寻功地面HIxa 理巧若敏并讦*乎坷同酣咐冲试验总设计流
2、程图:实用文档进程等待时间=进程开始运行时间一进程提交时间(即进程处于就绪态时间)进程周转时间=进程结束时间一进程提交时间【实验过程】(实验步骤、记录、数据、分析)测试用例1:屏幕显示:Please input the total number of jobs输入:4 屏幕显示:Please input job number, submit time and run time输入:19.00.228.50.538.01.049.10.1屏幕显示:What kind of algorithm do you want? Please input 1 to select FCFS, or 2 to
3、select SJF.输入:3 屏幕显示:You have input a wrong number, please input again.输入:1屏幕输出结果:submit run starting final wait turnaround38.01.08.09.00.01.028.50.59.09.50.51.0计成派计成派开始时间,结束时间等待时间,周转时间按照IO田排序_1FW报错继续输数计算各作业参数:弗雄蟀廊h据策憎间等待时间,周转时间并输出实用文档19.00.29.59.70.50.749.10.19.79.80.60.7屏幕显示:The average turnaround
4、 time is 0.85What kind of algorithm do you want? Please input 1 to select FCFS, or 2 to select SJF, or 0 to ex测试数据二:submitrun1 60.52 50.93 6.30.1FCFS和SJF算法结果一样:submitrun startingfinalwaitturnaround2 50.9 55.900.91 60.5 66.500.53 6.30.1 6.56.60.20.3The average turnaround time is 0.567测试数据三:submit run
5、150.224.20.335.10.345.20.1FCFS:submit runstartingfinalwait turnaround24.20.3 4.24.500.3150.2 55.200.235.10.3 5.25.50.10.445.20.1 5.55.60.30.4The average turnaround time is 0.325SJF:submit run starting final wait turnaround24.20.34.24.500.3150.255.200.245.20.15.25.300.135.10.35.35.60.20.5The average
6、turnaround time is 0.275源程序:#include stdio.h#include stdlib.h#include string.h#define M 50 struct sjf int jobnumber;实用文档float submittime;float runtime;float starttime;float finishtime;float waittime;float turnaroundtime;temp;static struct sjf stM;void input( struct sjf *p, int N)int i;printf( Please
7、 input the job number,submit time and run time:nFor exmple:1 8.5 2for (i =0;i N;i +)scanf( %d%f%f &pi . jobnumber, &pi . submittime, &pi . runtime);void print( struct sjf *p, int N)int k;float h,g;printf( run order: );printf( %d”,p0 . jobnumber);for (k =1;k %d ,pk . jobnumber);printf( nT
8、he processs information:n );printf(njobnumtsubmittruntstarttfinaltwaittturnaroundn);for (k =0;k N;k+)h+=pk . turnaroundtime;printf( %dt%-.1ft%-.1ft%-.1ft%-.1ft%-.1ft%-.1ftn,pk . jobnumber,pk . submittk . waittime,pk . turnaroundtime);g =h/ N;printf( nThe average turnaround time is %-.2fn,g);/*按提交时间从
9、小到大排序*/void sort1( struct sjf *p, int N)_int i,j;for (i =0;i N;i +)for (j =0;j =i;j +)if (pi . submittime pj . submittime)(temp =pi;实用文档pi =pj;pj =temp;/*运行*/void deal( struct sjf *p, int N)(int k;for (k =0;k pk-1 . finishtime)(pk . starttime =pk . submittime;pk . finishtime =pk . submittime +pk . r
10、untime;else(pk . starttime =pk -1. finishtime;pk . finishtime =pk -1. finishtime +pk . runtime;for (k =0;k N;k+)(pk . turnaroundtime =pk . finishtime - pk . submittime;pk . waittime =pk . starttime - pk . submittime;实用文档void sort2( struct sjf *p, int N)(int next,m,n,k,i;float min;sort1(p,N);for (m=0
11、;mpm-1 . finishtime)(pm . finishtime =pm. submittime +pm. runtime;elsepm . finishtime =pm-1. finishtime +pm. runtime;for (n =m+1;n N;n+)(if (pn . submittime =pm. finishtime) /*判断内存中每次完成之后乂多少到达的进i +;min =pm+1. runtime;next =m+1;for (k=m+1;k m+i;k +)/*找出到达后的进程中运行时间最小的进程*/(if (pk+1 . runtime 2兀一一JThe p
12、iocess,s information:obnurnubnitrunstartfinalwaitturnaround-8,01. 0a,og, o0 0L0Lc.0, 3Q. d9,09. S0.3L019.00. 29-59.70. 50.749.10. 1a. 79. S0.G0. 7The average traround tine s 0. 85ffhat kind of algorithm do you want? PLase input 1 to FCFS. or 2 cc selec t SJF or 0 toMH:2run order:3“142I:je proeesi7s
13、inf ornation:,obnuzsucnitrunstartfinalvaitturnaround-8.01. 0&09.00. 01.019.00 2g.o9.20 Q0.2y. 10. 19.30. 10.2-二8.50. 59,39. S0.81.3Ihe average turnaround time M 0* 67iVhat kind cf algorithm do vou want? PLease input 1 to select FCFS+or 2 to seleo测试二:Pleasel or exwle 111 9. 02 8 53 8.0the job nji
14、ntier, suLnit lirie and run time: & 5 2,0实用文档ncDlMXvYuVanXt inAitemp.ewe ithe total numiber of JDbs;3the job lumber, submit 1 ime and run tinted3. 5 2.03 6. 3 0. 1kind c-f algorithm do you want? Please inpuT 1 ro seLect FCFS. or 2 to selec t SJF or 0 ta ex t: r:in order:17一1-一3The proceus inform
15、ation:jobnumsuni trunstartfinal砒litturnaroundi-二5. 00. 95,05,9Q.O0.916. 00. 06.0&S0. 00.53630 I6.5& 60.20.3The aveiage t-irEarcund tine is 0. 57iV-iat kind al ori thm Ho 3PDUwant ? P .ease input 1 to select FCFSar 2 to select SJF or 0 to exit:2run order:2一1一3Izje pioces- - inf uznat ion;.obn
16、wnJUGElltrunstar!finalvaitturnaroundL5.00. 9.05. 90. 00. 91600 56.06.50 J0.536.30. L6.56.60.20.3The averturnaround t iw i 0. 57iVnat kind of algorithm do you wgi? FLcasc inpux 1 to scLcct FCFS* or 2 to sclec t SJF or 0 to exit;半:测试三:PledgeLlease inrut ForejiizpLe: 11 6 0.52 5 0. 9实用文档2 4, 2 0. 33 5.
17、 1 0. 34 5. 2 0- 1ffhot kind of nlsorihm do you wont? P ense input I toSFLCTFCFS, or 2 to selct SJF or 0 to exit:1run or der: 2一1 3一1I he prcfces i m infoymat ion :jobnun:Knitrunstartfinalvaitturnaround.A4.20 34.2150 00.315.00, 2o.Oo.20.00.235. 10. 35.25. 50. 10.1二二5.20 1三,a5, 60 sfl.4The average tu
18、rnaround time is 0.33Kiiit kind of al sat L t hm du you wantJ P lease input 1 to st Lee t FCS, ur 2 to selec t SJF ar 0 to exit:2 run order:2*1一一;一一 土The process* inforraaxian;zobnuzruntartfinalwaitturnaround二1. 20 34.250.00.35.00 2a,05,20 00.24o. 20, 10.23.3。00+1w5 10. 3二33.60. 20.5Ihe aveTage turn
19、around tine is 0. 27ri&t k;nd of alecrilrwi do you vajjt? Please input 1 to select FCF$. or 2 to selec t SJF nr ft to ?x:t:半,【小结】实验中产生的错误及原因分析:测试用例1的结果:错误1:实用文档ij 0;*inc2C 1Q4CYuVonbi nwwtcrnp cxcrm order: 3-21/4- The processs information:jobnun submit runstartfinalT?aitturnaround38. 01, 08. 09,
20、0Q 01.028.50.59. 09.50.51. 019.00.29. d9.70. o0,749一10,19 7璀o, e0.7The averagexurnarouncTime Is0, 8ohat kind of algorithm do you want? Please input 1 to select FCFS, or 2 t t SJF or 0 to exit:2 runorder;340-0The process1s information:j obnuiL sjbiiitrunstartfine!waitturnaround8.01.08. 09.00.01.09, 1
21、0. 19. 09. 1-0. 10.0(0.00,09. 10. 19, 19. 100.00.09. 19. 19. 19. 1The average turnaround time is 1. 80Khat kind of algorithm do you vant? Please input 1 tc select FCFS, or 2 tx SJF or 0 to exit:半:半:错误解决方式:主要是子函数sort2()中出的错:i的作用域,程序修改:将原来:int next,m,n,k,i=0;float min;sort1(p,N);for (m=0;mN;m+)改为:int
22、next,m,n,k,i;float min;sort1(p,N);for (m=0;mpm-1 . finishtime)(pm . finishtime =pm. submittime +pm. runtime;elsepm . finishtime =pm-1. finishtime +pm. runtime;测试用例3的结果:错误1:Flense顷ILease inrut ForejiEule: 11 6 0, 52 5 0.9iVhat kind oft SJF or 0 torun order:2-M-3T5e procesi,information:jebnuraEubmi tr
23、unstartfinnlwaitturnaround5. 00. 95.05. 90.00.9I6.00. 55.96. 1T. 10.1r6,30 16,46,5在1fl. 2The average ffiiiit kind ofdl11lull t SJF or t) toeKLt:.tineci. . - .:i .Fltase inpui 1 to select FCFS. g 2 toturnaroundQr50实用文档elsepm . finishtime =pm-1. finishtime +pm. runtime;修改为:elseif (pm . submittime pm-1
24、 . finishtime)pm . finishtime =pm. submittime +pm. runtime;elsepm . finishtime =pm-1. finishtime +pm. runtime; 实验的体会及收获:通过这次试验,我对处理机的调度算法特别是FCFS SJF有了更深的理解,而且锻炼了我的思维能力,使我能更全面地思考问题,以后还需要多做些这方面的练习。试验不足之处:未在子函数sort()中未考虑到提交时间(submittime)大于上个进程的结束时间”的情况:错误分析:同2一样,解决方法:将原来的:实用文档试验未考虑同一时间提交多个进程的情况,如:测试数据:
25、submitrun170.227.20.5370.1结果应该是:FCFS:submitrunstart finalwait turnaround170.27.07.50.00.5370.17.57.60.50.627.20.57.67.80.40.6The average turnaround time is 0.57.SJF:Jobnumsubmitrunstartingfinalwait turnaround370.17.07.10.00.1170.57.17.60.10.627.20.27.67.80.60.6The average turnaround time is 0.43.而程序
26、运行结果是:实用文档Please input the job number, t tine and run time;For exncle: 1&吕2, Q1 7 0. 5run order!1-*3?2The process* 5 information:-ebnumsubmitrunstartfinalwai tturnaround17.0O.o7.07. o0.00. 50. 637. 00. 17. 57. 60.52?, 20.27,67. 80,40 6The average turnaround 1imc is 0. 57kind of algorithm do you诉an匕!rit?i2The process s information;zobnmn submitrunat artfinal粗itt-jmaround17. 00.57.07. 50.005
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 毕业设计纪录片研究试题及答案
- 后厨帮工试题及答案
- 医师定期考核中西医结合骨伤科学专业试题及答案
- 2025-2030智慧酒店行业技术应用与发展模式优化研究
- 2025-2030智慧社区行业市场发展分析及投资前景研究报告
- 2025-2030智慧社区服务平台开发运营管理与投资价值评估
- 2025-2030智慧环保污染治理技术市场发展现状分析投资评估规划评估报告
- 2025-2030智慧物流行业风险评估及融资策略研究报告
- 2025-2030智慧物流行业市场运营分析成本评估销售规划研究报告
- 2025-2030智慧港口行业市场分析技术研究及投资战略规划报告
- 短视频在教育中的创新应用及发展前景
- 《复杂系统理论》课件
- 2025年个人参加巡察工作总结心得(二篇)
- 汽车维修配件供货及售后服务方案
- 基于物联网的智能设备销售合同
- 《铁路技术管理规程》(普速铁路部分)
- 2024年度广东省国家电网招聘之财务会计类通关题库(附答案)
- 《影院服务礼仪》课件
- 品管圈PDCA案例-普外科提高甲状腺手术患者功能锻炼合格率
- 人教版(2024新版)七年级上册生物第一单元 生物和细胞 模拟测试卷(含答案)
- TSG-R0004-2009《固定式压力容器安全技术监察规程》
评论
0/150
提交评论