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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

操作系统实验报告.docx

1、操作系统实验报告操作系统实验报告 班 级:计算机1007班 姓 名: 陶向东 学 号: 100511726 日 期: 2012.5.27 实验二 进程调度1目的和要求通过这次实验,理解进程调度的过程,进一步掌握进程状态的转变、进程调度的策略,进一步体会多道程序并发执行的特点,并分析具体的调度算法的特点,掌握对系统性能的评价方法。2实验内容阅读教材计算机操作系统第二章和第三章,掌握进程管理及调度相关概念和原理。编写程序模拟实现进程的轮转法调度过程,模拟程序只对PCB进行相应的调度模拟操作,不需要实际程序。假设初始状态为:有n个进程处于就绪状态,有m个进程处于阻塞状态。采用轮转法进程调度算法进行调

2、度(调度过程中,假设处于执行状态的进程不会阻塞),且每过t个时间片系统释放资源,唤醒处于阻塞队列队首的进程。程序要求如下:1)输出系统中进程的调度次序;2)计算CPU利用率。3实验环境Windows操作系统、VC+6.0C语言4设计思想1) 程序中进程可用PCB表示,其类型描述如下: struct PCB_type int pid ; /进程名int state ; /进程状态 2表示“执行”状态 1表示“就绪”状态 0表示“阻塞”状态 int cpu_time ; /运行需要的CPU时间(需运行的时间片个数) 2) 设置两个队列,将处于“就绪”状态的进程PCB挂在队列ready中;将处于“阻

3、塞”状态的进程PCB挂在队列blocked中。 队列类型描述如下: struct QueueNode struct PCB_type PCB; Struct QueueNode *next;并设全程量:struct QueueNode *ready_head=NULL, /ready队列队首针*ready_tail=NULL , /ready队列队尾指针*blocked_head=NULL, /blocked队列队首针*blocked_tail=NULL; /blocked队列队尾针3)设计子程序: start_state(); /读入假设的数据,设置系统初始状态dispath(); /模拟调

4、度 calculate(); /计算CPU利用率5. 源程序#include #include #include #include using namespace std;struct PCB_type int pid ; /进程名 int state ; /*进程状态 2-表示执行状态 1-表示就绪状态 0-表示阻塞状态*/ int cpu_time ; /运行需要的CPU时间(需运行的时间片个数) ; struct QueueNode struct PCB_type PCB; struct QueueNode *next; struct QueueNode *ready_head=NULL

5、; /ready队列队首指针 struct QueueNode *ready_tail=NULL; /ready队列队尾指针 struct QueueNode *blocked_head=NULL; /blocked队列队首指针 struct QueueNode *blocked_tail=NULL; /blocked队列队尾指针 int use_cpu,unuse_cpu; void start_state() int i,m,n,k; struct QueueNode *p; cout请输入就绪队列个数m和阻塞队列个数nmn; p=(struct QueueNode *)malloc(si

6、zeof(struct QueueNode); p-next=NULL; ready_head=ready_tail=p; cout就绪队列进程:endl; for(i=1;inext=NULL; cout请输入第i个就绪进程的pid和cpu_timep-PCB.pidp-PCB.cpu_time; p-PCB.state=1; ready_tail-next=p; ready_tail=p; k=1; p=ready_head-next; while(p) cout第k个就绪进程的pid和cpu_time分别为:PCB.pid PCB.cpu_timenext; k+; p=(struct

7、QueueNode *)malloc(sizeof(struct QueueNode); p-next=NULL; blocked_head=blocked_tail=p; cout阻塞队列进程:endl; for(i=1;inext=NULL; cout请输入第i个阻塞进程的pid和cpu_timep-PCB.pidp-PCB.cpu_time; p-PCB.state=0; blocked_tail-next=p; blocked_tail=p; k=1; p=blocked_head-next; while(p) cout第k个阻塞进程的pid和cpu_time分别为:PCB.pid P

8、CB.cpu_timenext; k+; void dispath() struct QueueNode *p; int x=0,t; coutt; use_cpu=0; unuse_cpu=0; while(ready_head!=ready_tail|blocked_head!=blocked_tail) if(ready_head!=ready_tail) p=ready_head-next; ready_head-next=p-next; p-next=NULL; if(ready_head-next=NULL) ready_tail=ready_head; p-PCB.state =

9、2; cout运行进程:PCB.pidPCB.cpu_time-; use_cpu+; if(p-PCB.cpu_time) p-PCB.state=1; ready_tail-next=p; ready_tail=p; ready_tail-next=NULL; else coutendl; cout进程PCB.pid运行完成!endl; coutendl; free(p); else coutCPU未运行!next; blocked_head-next=p-next; p-next=NULL; if(blocked_head-next=NULL) blocked_tail=blocked_

10、head; ready_tail-next=p; ready_tail=p; ready_tail-next=NULL; p-PCB.state=1; x=0; void calculate() coutCPU利用率为:(use_cpu/double(use_cpu+unuse_cpu)*100%next=NULL; / 创建自由链头结点busy_head=busy_tail=(struct busylink*)malloc(sizeof(struct busylink); busy_head-next=NULL; / 创建占用链头结点 p=( struct freelink *)malloc

11、(sizeof(struct freelink); p-address=64; p-len=640-64; (OS占用了64K) p-next=NULL; free_head-next=p; q=( struct busylink *)malloc(sizeof(struct busylink); q-name=S; /* S表示操作系统占用 */ q-len=64; q-address=0; q-next=NULL; busy_head-next=q; busy_tail=q; void requireMemo(char name, int require); /*模拟内存分配*/ void

12、 freeMemo(char name); /* 模拟内存回收*/ void past(int time); /* 模拟系统过了time 时间*/ void printlink(); /* 输出内存空闲情况(自由链的结点) */ 3.设计主函数:main() start(); past(t1); requireMemo(A,8); requireMemo(B,16); requireMemo(C,64); requireMemo(D,124); printlink(); past(t2); freeMemo(C); printlink(); past(t3); requireMemo(E,50

13、); printlink(); freeMemo(D ); printlink();5. 源程序#include #include #include #include using namespace std;struct freelink int len, address; /* len为分区长度 */ /* address为分区起始地址 */ struct freelink *next;struct busylink char name; /* 作业或进程名 name=S 表示OS占用*/ int len , address; struct busylink *next;struct fre

14、elink *free_head=NULL; /自由链队列(带头结点)队首指针 struct busylink *busy_head=NULL; /占用区队列队(带头结点)首指针 struct busylink *busy_tail=NULL; /占用区队列队尾指针void start(void) /* 设置系统初始状态*/ struct freelink *p; struct busylink *q; free_head=(struct freelink*)malloc(sizeof(struct freelink); free_head-next=NULL; / 创建自由链头结点 busy

15、_head=busy_tail=(struct busylink*)malloc(sizeof(struct busylink); busy_head-next=NULL; / 创建占用链头结点 /初始空闲链表 p=( struct freelink *)malloc(sizeof(struct freelink); p-address=64; p-len=640-64; /(OS占用了64K) p-next=NULL; free_head-next=p; /初始被占用链表 q=( struct busylink *)malloc(sizeof(struct busylink); q-name

16、=S; /* S表示操作系统占用 */ q-len=64; q-address=0; q-next=NULL; busy_head-next=q; busy_tail=q; void requireMemo(char name, int require) /*模拟内存分配*/ if(free_head-next-lenname=name; p-address=free_head-next-address; p-len=require; p-next=NULL; busy_tail-next=p; busy_tail=p; w=free_head-next; free_head-next=w-n

17、ext; if(w-len=require) free (w); else w-address=w-address+require; w-len=w-len-require; struct freelink *u,*v; u=free_head; v=free_head-next; while(v!=NULL)&v-lenw-len) u=v; v=v-next; u-next=w; w-next=v; void freeMemo(char name) /* 模拟内存回收*/ struct busylink *p,*q; struct freelink *w,*u,*v; int len,ad

18、dress; q=busy_head; p= busy_head-next; while(p!=NULL&(p-name!=name) q=p; p=p-next; if(p=NULL) printf(%c is not exist,name); else if(p=busy_tail) busy_tail=q; else q-next=p-next; len=p-len; address=p-address; free(p); w=( struct freelink*) malloc(sizeof(struct freelink); w-len=len; w-address=address;

19、 u=free_head; v=free_head-next; while(v!=NULL&v-lenw-len) u=v; v=v-next; u-next=w; w-next=v; void past(int time)/* 模拟系统过了time 时间*/ cout经过时间time后:next; while(v!=NULL) cout第i个空闲分区信息为:; coutaddress:address len:lennext; i+; coutnext; while(v!=NULL) cout第i个工作分区信息为:; coutaddress:address len:lennext; i+; c

20、outendl; void main(void) start(); past(1); requireMemo(A,8); requireMemo(B,16); requireMemo(C,64); requireMemo(D,124); printlink(); printlink2(); past(3); freeMemo(C); printlink(); printlink2(); past(4); requireMemo(E,50); printlink(); printlink2(); past(5); freeMemo(D ); printlink(); printlink2();6.实例运行结果7.实验总结此次实验通过C语言程序动态地模拟了操作系统中内存的动态分区分配。 此次实验通过建立结点来模拟空闲分区和已占用分区,每个表示空闲分区或已占用分区的结点都包括有次空闲分区的大小和内存地址以及一个指向下一个空闲或占用分区的结构体指针,通过结点形成空

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

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