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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

操作系统实验报告__实验一.docx

1、昆明理工大学信息工程与自动化学院学生实验报告( 2012 2013 学年 第 二学期 )课程名称:操作系统开课实验室:信自楼 445 2011 年 4 月18 日年级、专业、班学号姓成绩名实验项目名称进程管理指导教师舒国锋教师评 教师签名:语 年 月 日一、实验要求:对一个非抢占式多道批处理系统采用以下算法的任意两种,实现进程调度,并计算进程的开始执行时间,周转时间,带权周转时间,平均周转时间,平均带权周转时间1. 先来先服务算法2. 短进程优先算法3. 高响应比优先算法二、实验目的通过编写进程管理的算法,要求学生掌握整个进程管理的各个环节,进程的数据结构描述, 进程的各种状态之间的转换,以及

2、进程的调度算法。以加深对进程的概念及进程调度算法的理解,并且提高链表的应用能力,达到提高编程能力的目的。三、实验原理及基本技术路线图(方框原理图)输入开始进程数n创建n 个 PCB 并加入 readyqueue 中ready-queue 是否为Y-1-用C 语言或 C+语言开发。需要定义 PCB 的数据结构,用链表的形式管理进程,采用多级反馈队列调度的算法模拟进程的控制。要求有创建、撤销、调度、阻塞、唤醒进程等功能。输入开始进程数n创建n 个 PCB 并加入 readyqueue 中ready-queue 是否为YNRunning逐个将 redy_pc 中的 PCB-2-Running=idN

3、Running=idRunning逐个将 redy_pc 中的 PCBN阻塞 RunningYRunning=idleNY将Running 从 ready_queue中删除,再将 running 加入 block_queueb更新新进程就绪队列进程优先数,优先数加1N是否创建新 PCBY创建新进程并加入到ready_queue 中随机 对 block_queue 中的进程 PCB 询问是否要唤醒?Y处理完了吗NN是否要唤醒Y将其从 blick_queuek 队列是中删除,再将其加入ready_queuekN阻塞RunningYYRunning=idleN将Running 从 ready_que

4、ue中删除,再将 running 加入 block_queuebN是否创建新 PCBY创建新进程并加入到ready_queue 中随机 对 block_queue 中的进程 PCB 询问是否要唤醒 ?Y处理完了吗NN是否要唤醒Y将其从 blick_queuek 队列是中删除,再将其加入ready_queuekY四、所用仪器、材料(设备名称、型号、规格等)。计算机一台五、实验方法、步骤源代码:#include stdio.h #include stdlib.h #include iostream.h #define NULL 0 #define false 0 #define true 1 bo

5、ol _state=0; -5-struct PCB int ID; int priority; int CPUtime; int ALLtime; int State; PCB* next; ; void init();/*产生 idle 进程,输入用户进程数目,调用insert()*/ void print(PCB *pcb);/*输出进程属性信息*/ void print_init(PCB *pcb);/*输出所有 PCB 的初始值*/ void insert();/*生成进程属性信息,插入进程就绪队列*/ void Run_priority(PCB *pcb);/*运行进程,随机阻塞进

6、程、产生新进程,插入就绪队列,唤醒阻塞进程*/ void block(PCB *pcb);/*调用 destroy()将进程插入阻塞队列*/ void wakeup();/*唤醒进程,插入就绪队列*/ void proc_priority();/*优先权调度算法模拟*/ /void Run_loop(PCB *pcb); void proc_loop();/*轮转法调度算法模拟*/ void update(PCB *pcb);/*更新进程信息*/ void pushback_queue(PCB *queue,PCB *item);/*将 item 插入到队列的尾部*/ void insert_

7、queue(PCB *queue,PCB *item);/*将 item 插入到队列中,使得插入后,队列中按照优先级从高到低有序*/ void sort_queue(PCB *&queue);/*对 queue 中的结点进行排序,按照优先级从大到小*/ PCB *ready_queue,*block_queue,*idleprocess;/*就绪队列,阻塞队列及闲逛进程指针变量*/ int main(int argc, char* argv) int i=0; while(1) cout*PROCESS*/; cout(n Please select a num in(1,2,0) ); co

8、ut(n 1-priority ); cout(n 2-loop ); cout(n 0- exitn); couti; while(i) if(i=1) cout(n This is a example for priority processing: n ); init(); proc_priority(); else if (i=2) cout(n This is a example for round robin processing: n ); init(); proc_loop(); else coutPlease select a num in(1,2,0)n; couti; r

9、eturn 0; void print_init(PCB *pcb)/输出所有 PCB 的初始值 PCB* temp=pcb-next ; cout(nID priority CPUtime ALLtime State); while(temp!=NULL) coutnIDpriorityCPUtime ALLtime; if(temp-State=0) coutState =1) cout( running); else coutnext; void print(PCB *pcb)/输出进程属性信息 PCB *temp; temp=pcb; if(pcb-ID=0) cout(nThe id

10、le peocess id running!); else coutnIDpriorityCPUtime ALLtime; if(temp-State=0) coutState =1) cout( running); -6-else coutnext; while(p!=0&p-priority=item-priority) q=p; p=p-next; if(p=0) item-next =0; q-next=item; else item-next =p; q-next =item; void pushback_queue(PCB *queue,PCB *item)/将 item 插入到阻

11、塞队列的尾部 PCB *p,*q; q=queue,p=q-next; while(p!=0) -16- q=p; p=p-next; item-next =q-next ; q-next =item; void sort_queue(PCB *&queue)/对 queue 中的结点进行排序,按照优先级从大到小 PCB *temp=new PCB; temp-next =0; while(queue-next ) PCB *p; p=queue-next; queue-next =p-next ; insert_queue(temp,p); queue-next =temp-next ; d

12、elete temp; void insert()/生成进程属性信息,插入进程就绪队列,显示进程信息 PCB *newp=0; static long id =0; newp=new PCB; id+; newp-ID =id; newp-State=0; newp-CPUtime=0; newp-priority=rand()%3+1; newp-ALLtime=rand()%3+1; newp-next =NULL; pushback_queue(ready_queue,newp); /print(newp); /cout readyn); void insert(int n)/生成 n

13、个进程属性信息,插入进程就绪队列,显示进程信息 for(int i=0;inext=0; ready_queue=new PCB; ready_queue-next=0; int i=0,pcb_number=-1;/*闲逛进程放入就绪队列*/ idleprocess=NULL; idleprocess=(PCB *)malloc(sizeof(PCB); idleprocess-ID=0; idleprocess-State=0; idleprocess-CPUtime=0; idleprocess-priority=0; idleprocess-ALLtime=0; idleprocess

14、-next=NULL; idleprocess-next=ready_queue-next;/*闲逛进程放入就绪队列*/ ready_queue-next=idleprocess; /也可以假定初始时系统中只有一个idle 进程/输入初始进程的个数 while(pcb_number0) coutpcb_number; cout(nID priority CPUtime ALLtime Staten); for(;ipcb_number;i+) insert(); cout*就绪队列初始化成功endl; :print_init(ready_queue); coutState=2; pcb-CPU

15、time-=2; if(pcb-CPUtimeCPUtime+=2; coutnThe process noID is blocked!; print(pcb); cout blockedn); pcb-next=block_queue-next; block_queue-next =pcb; void update(PCB *pcb)/更新进程信息,就绪队列中进程的优先级均增加1 PCB *temp=pcb-next; while(temp&temp-next ) temp-priority+; temp=temp-next; void wakeup()/唤醒进程,插入就绪队列 if(blo

16、ck_queue-next=0)/*此时没有阻塞的进程,无所谓的唤醒*/ return ; PCB *q,*p; while(true) q=block_queue; p=q-next; while(p&rand()%20!=1) q=p; p=p-next; if(p!=0) q-next =p-next ; break; p-State=0; coutendl; print(p); cout readyID=0) insert_queue(ready_queue,pcb); print(pcb); cout runningn; else pcb-State=1; pcb-CPUtime+=

17、4; pcb-priority=pcb-priority -3;/*每运行一个时间片,其优先数减3*/ if(pcb-priority priority=1; print(pcb); printf( 变 迁 1: ready - runningn); if(rand()%3=1)/*PCB不是闲逛进程,满足条件侧阻塞此进程*/ if(pcb-CPUtime-2ALLtime) block(pcb); else/*已执行完毕,应该销毁进程*/ coutn; coutThe process noIDDestroyCPUtime=pcb-ALLtime)/*释放*/ coutn; coutThe p

18、rocess no ID DestroryID=0) insert_queue(ready_queue,pcb); print(pcb); cout runningn; else pcb-State=1; pcb-CPUtime=pcb-ALLtime; print(pcb); printf( 变 迁 1: ready - runningn); if(rand()%3=1)/*PCB不是闲逛进程,满足条件侧阻塞此进程*/ _state=1; block(pcb); else coutn; coutThe process no ID Destroryendl; delete pcb; if(ra

19、nd()%5=1) insert(3); if(rand()%7=1) wakeup(); void proc_priority()/优先权调度算法模拟 sort_queue(ready_queue); PCB *temp=0,*running=0; int times=0; cout*调度前:; :print_init(ready_queue); for(;timesnext; ready_queue-next =running-next ; coutendl; cout*调度开始endl; Run_priority(running); coutn*本次调度结束。endl; void pro

20、c_loop()/轮转调度算法模拟 PCB *temp=0,*running=0; int times=10; coutnext; ready_queue-next =running-next ; cout0) times=times-running-ALLtime;/*每次运行一个进程减去ALLtime;*/ if(times=0) Run_loop(running); else if(_state)/*如果运行时被阻塞,则运行2 个时间单位*/ times=times+2; _state=0; cout5487584574389574 fgfgfgfgf gfgfg389543789543

21、75894378954375; else pushback_queue(block_queue,running);/*时间不过,则阻塞该进程,放到阻塞队列 */ else if(times=0) coutn*本次调度时间片到!; break; coutn*本次调度结束。endl; 六、实验过程原始记录(数据、图表、计算等) 运行截图:七实验、析和结-19-(误差分析与数据处理、成果总结等。其中,绘制曲线图时必须用计算纸)此次实验是编写进程管理的算法,程序包括了创建、撤销、调度、阻塞、唤醒进程等功能,该程序使用C+语言。由于基础知识的不牢固以及没有对所学知识的即使复习,在做的过程中有很大的难度,

22、因此,又对C+的一些运用进行了复习,重新看了一遍有关进程的相关知识,加深了对 C+知识的运用以及进程知识的了解。在此次程序中,我们主要运用的还是函数的调用以及队列的运用,因此,此次试验还运用了很多数据结构的知识,需充分的利用我们所学知识。在编写程序过程中,我们首先对变量进行初始化,然后建立进程函数、输出进程属性信息函数、输出所有 PCB 的初始值、生成进程属性信息,插入进程就绪队列、运行进程,随机阻塞进程、产生新进程,插入就绪队列,唤醒阻塞进程等等,然后对这些函数进行调用,我们才能编写出一个完整的程序, 最后再对程序进行调试。在调试的过程中,出现了很多的错误,但都是一些常见的错误, 因此通过软件的提醒都能够自己解决。此次程序包含的内容很多,是学习程序语言来很少遇到的一次挑战。但在程序的辨析过程中也学到了很多,不但把自己遗忘的进行了复习, 而且还学到了新的知识,虽然不是把每个方面都理解透彻了,但是至少能够理解它的相关功能以及需要实现的目的。

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2