【2017年整理】操作系统实验报告

上传人:爱****1 文档编号:942163 上传时间:2017-05-23 格式:DOC 页数:18 大小:258KB
返回 下载 相关 举报
【2017年整理】操作系统实验报告_第1页
第1页 / 共18页
【2017年整理】操作系统实验报告_第2页
第2页 / 共18页
【2017年整理】操作系统实验报告_第3页
第3页 / 共18页
【2017年整理】操作系统实验报告_第4页
第4页 / 共18页
【2017年整理】操作系统实验报告_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《【2017年整理】操作系统实验报告》由会员分享,可在线阅读,更多相关《【2017年整理】操作系统实验报告(18页珍藏版)》请在金锄头文库上搜索。

1、淮 阴 工 学 院实 验 报 告_2012 _-_2013_学年 第_1_学期学 院_计算机工程学院_课程名称_操作系统 _班 级_软件 1101_学 号_1101305114_姓 名_王 祥_指导教师_严云洋_实验一:进程调度1. 实验目的:通过这次实验,加深对进程概念的理解,进一步掌握进程状态的转变、进程调度的策略及对系统性能的评价方法。2. 实验内容:设计程序模拟进程的轮转法调度过程。假设初始状态为:有 n 个进程处于就绪状态,有 m 个进程处于阻塞状态。采用轮转法进程调度算法进行调度(调度过程中,假设处于执行状态的进程不会阻塞),且每过 t 个时间片系统释放资源,唤醒处于阻塞队列队首的

2、进程。程序要求如下:1).输出系统中进程的调度次序;2).计算 CPU 利用率。3. 实验环境:硬件环境:Ghost XP SP3 纯净版 Y6.0 Pentium(R) Dual-Core CPU E6700 3.20GHz 3.19 GHz, 1.96 GB 的内存物理地址扩展软件环境:Microsoft Windows XP , Visual Studio 20084. 源代码:#include #include #include using namespace std;onst int MaxNum = 100;struct Nodeint index;int arriveTime;i

3、nt rest;bool NodeCmp(const Node& a,const Node& b)return a.arriveTime & que,Node* pArr,int maxArrivalTime)int i;for(i=0;imaxArrivalTime)break;if(isEnterQuepArri.index=false)que.push(pArri);isEnterQuepArri.index = true;void Work(int q)init();memset(isEnterQue,0,sizeof(isEnterQue);memset(cntTimes,0,siz

4、eof(cntTimes);Node* pNodeArr = new Noden;int i;for(i=0;i que;que.push(pNodeArr0);isEnterQuepNodeArr0.index=true;Node cur;cout q)time += q;cur.rest -= q;elsetime += cur.rest;Finishedcur.index=true;FinishTimecur.index = time;cur.rest = 0;printf(在%d时刻,进程%d执行结束。n,time,cur.index);SearchToEnterQue(que,pNo

5、deArr,time);if(cur.rest!=0)que.push(cur);if(que.empty()/若队列为空,则在time之后才达到的进程找最早到达的进程入队列for(i=0;in;coutArrivalTimei;coutServiceTimei;coutq;Work(q);return 0;5. 实验结果:6. 试验分析和体会:实验二 分区式存储管理1. 实验目的:通过这次实验,加深对内存管理的认识,进一步掌握内存的分配、回收算法的思想。2. 实验内容:设计程序模拟内存的动态分区法存储管理。内存空闲区使用自由链管理,采用最坏适应算法从自由链中寻找空闲区进行分配,内存回收时假定

6、不做与相邻空闲区的合并。假定系统的内存共 640K,初始状态为操作系统本身占用 64K。在 t1 时间之后,有作业 A、B 、C 、 D 分别请求 8K、16K 、64K 、124K 的内存空间;在 t2 时间之后,作业 C 完成;在 t3 时间之后,作业 E 请求 50K 的内存空间;在 t4 时间之后,作业 D 完成。要求编程序分别输出 t1、t2、t3、t4 时刻内存的空闲区的状态。3. 实验环境:硬件环境:Ghost XP SP3 纯净版 Y6.0 Pentium(R) Dual-Core CPU E6700 3.20GHz 3.19 GHz, 1.96 GB 的内存物理地址扩展软件环

7、境:Microsoft Windows XP , Visual Studio 20084. 源代码:#include stdafx.h#include#includestruct freelinkint len, address; / len为分区长度;address为分区起始地址struct freelink * next;/内存占用区用链表描述,其结点类型描述如下:struct busylinkchar name; / 作业或进程名 name=S 表示OS占用int len , address;struct busylink *next; ;/并设全程量:struct freelink *

8、free_head=NULL; / 自由链队列带头结点)队首指针? struct busylink *busy_head=NULL, *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_head=busy_tail

9、=(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占用了K)p-next=NULL; free_head-next=p;q=( struct busylink *)malloc(sizeof(struct busylink);q-name=S; /* S表示操作系统占用 */q-len=64; q-address=0;

10、 q-next=NULL;busy_head-next=q; busy_tail=q;void requireMemo(char name, int require) /*模拟内存分配*/struct freelink *w,*u,*v,*x,*y;struct busylink *p;x=free_head;y=free_head-next;while(y!=NULL) &(y-lennext;if(y!=NULL)p=(struct busylink*)malloc(sizeof(busylink);p-name=name;p-address=y-address;p-len=require

11、; p-next=NULL;busy_tail-next=p; /把p插入到busy_head的尾部busy_tail=p;w=x-next;x-next=w-next;if(w-len=require)free(w);elsew-address=w-address+require;w-len=w-len-require;u=free_head;v=free_head-next;while(v!=NULL) & (v-lenlen)/如果此结点还有多余,就此又重新插入到空闲区域链中(按照长度由小到大的次序排列)u=v;v=v-next;u-next=w;w-next=v;else printf

12、(cant allocate!n);void freeMemo(char name) /* 模拟内存回收*/ struct busylink *p,*q;struct freelink *w,*u,*v,*s1=NULL,*s2=NULL;int len,address;int flag1=1,flag2=1;p=busy_head-next;while(p!=NULL)&(p-name!=name) /找到要回收的结点q=p;p=p-next;if(p=NULL)printf(%c is not existn,name);elseif (p=busy_tail) busy_tail=q;q-

13、next=p-next;len=p-len;address=p-address;free(p);w=(struct freelink*) malloc(sizeof(freelink);w-len=len;w-address=address;u=free_head;v=free_head-next;while(v!=NULL) & (flag1=1 | flag2=1) /归并算法if(w-address=(v-address+v-len) &flag1) s1=v;u-next=s1-next;w-address=v-address;w-len+=v-len;v=v-next;flag1=0

14、;else if(w-address+w-len)=v-address) &flag2)s2=v;u-next=s2-next;w-len+=v-len;v=v-next;flag2=0;elseu=v;v=v-next;if(s1!=NULL)free(s1);if(s2!=NULL)free(s2);u=free_head;v=free_head-next;if(v!=NULL)while(v!=NULL) & (v-lenlen)u=v;v=v-next;u-next=w;w-next=v;void past(int time) /* 模拟系统过了时间time,用sleep(),或者用个

15、空循环*/printf(时间%d后:n,time);void printlink() /* 输出内存空闲情况(自由链的结点)*/ struct freelink *p;p=free_head-next;if(p=NULL)printf(无空闲区!n);elsewhile(p!=NULL)printf(首地址:%dt长度:%dn,p-address,p-len);p=p-next;printf(-n);void printlink1() /* 输出内存占用的情况*/ struct busylink *p;p=busy_head-next;if(p=NULL)printf(无内存占有区!n);elsewhile(p!=

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 研究报告 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号