ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:18.50KB ,
资源ID:7765231      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/7765231.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(进程调度实验报告.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

进程调度实验报告.docx

1、进程调度实验报告天津大学仁爱学院操作系统实验报告实验类型:必修实验日期: 2014年 4月 18日实验名称:进程调度实验地点:二实验楼 504学生姓名:李帅帅 指导教师:张 磊班 级:计科一班计算机科学与技术系实验报告内容:1) 实验目的用c语言编写和调试一个进程调度程序,以加深对进程的概念及进程 调度算法的理解。2) 实验器材和设备硬 件:二实验楼504计算机开发工具: Microsoft Visual C+ 6.03) 实验任务本实验模拟单处理器系统的进程调度,加深对进程的概念及进程调度算 法的理解。用c语言编写和调试一个进程调度的算法程序,有一些简单的界 面,能够运行,仿真操作系统中进程

2、调度的原理和过程。通过对调度算法的 模拟,进一步理解进程的基本概念,加深对进程运行状态和进程调度4) 实验原理无论是在批处理系统还是分时系统中,用户进程数一般都多于处理机 数、这将导致它们互相争夺处理机。另外,系统进程也同样需要使用处理 机。这就要求进程调度程序按一定的策略,动态地把处理机分配给处于就 绪队列中的某一个进程,以使之执行。 基本状态:1.等待态:等待某个事件的完成;2.就绪态:等待系统分配处理器以便运行;3.运行态:占有处理器正在运行。运行态-等待态 往往是由于等待外设,等待主存等资源分配或等待人工干 预而引起的。等待态-就绪态则是等待的条件已满足,只需分配到处理器后就能运行。

3、运行态-就绪态 不是由于自身原因,而是由外界原因使运行状态的进程让 出处理器,这时候就变成就绪态。例如时间片用完,或有更高优先级的进程 来抢占处理器等。就绪态-运行态 系统按某种策略选中就绪队列中的一个进程占用处理器, 此时就变成了运行态5) 实验过程描述a) 打开 Microsoft Visual C+ 6.0 ,创建工程。b) 根据要求用c语言代码实现应用程序,并调试完成c) 运行程序,根据提示输入相应的字符。d) 输入实验测试内容,并观察执行窗口显示的过程。e)重复c、d过程,认真体会领悟。6)实验代码 / Iss.cpp : Defines the entry point for th

4、e con sole applicatio n. /#include stdafx.h#include #include vconio.h#include #include #define P_NUM 3 #define P_TIME 50 enu mstate ready, execute, block, fin ish;structpcbchar n ame4;intpriority;intcputime;intn eedtime;intcount;intround;state process;pcb* n ext;pcb * get_process() _pcb *q;pcb *t;pc

5、b *p;int i=0;t=( struct pcb *)malloc( sizeof (pcb); p=(struct pcb *)malloc( sizeof (pcb); cout Input Name and Time endl;while (iq-n ame;cinq-n eedtime;q-cputime=O;q-priority=P_TIME-q-n eedtime;q-process=ready;q-n ext=NULL;if (i=0)p=q;t-n ext=q;elseq-n ext=t- n ext;t=q;q=p;i+;return p;void display(pc

6、b * p)coutname cputime needtime priority state endl;while (p)coutn ame;cout;coutcputime;cout;coutn eedtime;cout;coutpriority;coutprocess)case ready:cout ready endl; break;case execute:cout execute endl; break;case block:cout block endl; break;case finish:cout finish n ext;int process_finish(pcb *q)

7、_int b1=1;while (b1 &q)b1=b1 &q-n eedtime=O; q=q-n ext;return b1;void cpuexe(pcb *q)pcb *t=q;int tp=0;while (q)if (q-process!=finish) q-process=ready;if (q-needtime=0) q-process=fi ni sh;if (tppriority&q-process!=finish) tp=q-priority; t=q; q=q-n ext;if (t-needtime!=0) t-priority-=3; t-n eedtime-;t-

8、process=execute; t-cputime+;void priority_cal() _pcb * p;system(cls);P=get_process();int cpu=0;system( cls);while (!process_finish(p) _cpu+;cout cuptime: cpuendl;cpuexe(p);display(p);Sleep(1000);printf( All processes have fini shed,press any key to exit );getch();void display_menu() _coutnCHOOSE THE

9、 ALGORITHMKe ndl;cout1 PRIORITYe ndl;cout 2 roun drob in e ndl;cout 3 EXIT endl;/显示调度算法菜单,可供用户选择优先权调度算法和时间轮转调度算法pcb *get_process_r oun d() 一 一pcb *q;pcb *t;pcb *p;int i=0;t=( struct pcb *)malloc( sizeof (pcb);p=(struct pcb *)malloc( sizeof (pcb);cout in put n ame and time e ndl;while (iq-n ame;cinq-

10、n eedtime;q-cputime=0;q-roun d=0;q-co un t=0;q-process=ready;q-n ext=NULL;if (i=0)p=q;t-n ext=q;elseq-n ext=t- n ext; t=q; q=p;i+;return p;void cpu_round(pcb *q) _q-cputime+=2;q-n eedtime-=2;if (q-needtimen eedtime=0;q-co un t+;q-roun d+; q-process=execute;pcb * get_ next(pcb * k,pcb * head) _pcb *

11、t;t=k;dot=t- n ext;while (t&t-process=finish);if (t=NULL)t=head;while (t-next!=k&t-process=finish) return t; void set_state(pcb *p) _while (p)if (p-needtime=0)p-process=fi ni sh;/如果所需执行时间为0,则设置运行状态为结束if (p-process=execute) p-process=ready; /如果未执行状态则设置为就绪p-n ext;/设置队列中进程执行状态void displayound(pcb *p) _

12、coutvvNAME QPUTIMEV vvNEEDTIME COUNTROUNDSTATEendl;while (p)coutn ame;cout ;coutcputime;cout ;coutn eedtime;cout ;coutco unt;cout ;coutr ound;coutprocess)case ready:cout ready endl; break; case execute:cout execute endl; break; case finish:cout finish n ext;时间片轮转调度算法输出调度信息void round_cal() _pcb * p;p

13、cb * r;system(cls);P=get_process_r oun d();int cpu=0;system( cls);r=p;while (!process_finish(p) _cpu+=2;cpu_ro un d(r);r=get_ next(r,p);cout cpu cpuendl; display_r oun d(p);set_state(p);Sleep(1000);int main( int argc, char* argv)display_me nu();int k;scanf( %d,&k);while (1)switch (k)case 1:priority_

14、cal(); break;case 2:ro un d_cal(); break;case 3: return 0;display_me nu(); scanf( %d,&k);printf( n本调度算法成功结束! n;);return 0;7)实验结果截图g 作系统上机lssDebuglss. ezeeput ime-1name eputineneedt imepriority staA 111 35executeeputinename eput imeneedt imepriority statea 210 32executec put ime: 3name eputimeneedt i

15、meprior ity statea 39 29executecputime:4name eputineneedtinepriority statea 48 26executeeput inc-5Iname eput imeneedt imepriority state卜57 23executeleput imeIname Cput imeinepriority StateU 66 20executeeput irie: 7namQ cpu,t ineneedt imepriority staA 75 17executeeput ime-Sname eput imeneedt imeprior

16、ity statea 84 14exedutfteput ime:9name c put imeneedtimepriority state鬲 ?3 11executeeput line : 18nan? cpu,t inene ed incpr*ioi*i ty s ta 七日a 102 8execueput ime-11name eputineneedt imepriority state& 111 Sexecuteeputime:12name eput imeneedt imepriority statea 120 2executehave f in is hcd, press an*/ key to exitAll processesCHOOSE THE ALGORITHM:1PRIORITY2POUNVROBIN3EXITJ8)对实验的总结本次实验,任务是用c语言代码实现进程调度模拟系统,从而观察进 程的运行过程及加深对进程的了解。这次实验,加深了我对进程概念及进 程调度的理解;熟悉了进程调度算法。使得理论知识得到的实践,也使我 的编程能力得到了进一步提高。实验中,我们小组共同学习、共同努力, 虽然在实验中遇到了一些问题,但在查阅资料后都解决了。实验过程也让 我认识到自己的不足,好多知识已经模糊不清,在今后自己要多一些实验 及相关的小项目,来提高自己的编程能力。

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1