操作系统实验报告 下载本文

内容发布更新时间 : 2024/5/20 18:06:21星期一 下面是文章的全部内容请认真阅读。

三状态之间的变迁。懂得调式的重要性。总之,我们明白了理论联系实际。多看书,多上机。 实验三可变分区存储管理 1.目的和要求

通过这次实验,加深对内存管理的认识,进一步掌握内存的分配、回收算法的思想。 2.实验内容

阅读教材《计算机操作系统》第四章,掌握存储器管理相关概念和原理。

编写程序模拟实现内存的动态分区法存储管理。内存空闲区使用自由链管理,采用最坏适应算法从自由链中寻找空闲区进行分配,内存回收时假定不做与相邻空闲区的合并。

假定系统的内存共640K,初始状态为操作系统本身占用64K。在t1时间之后,有作业A、B、C、D分别请求8K、16K、64K、124K的内存空间;在t2时间之后,作业C完成;在t3时间之后,作业E请求50K的内存空间;在t4时间之后,作业D完成。要求编程序分别输出t1、t2、t3、t4时刻内存的空闲区的状态。 3.实验环境

Windows操作系统、VC++6.0 C语言 4.设计思想

模拟内存分配和回收,要设置两个链队列,一个空闲区链和一个占用区链,空闲区链节点有起始地址,大小和指向下一节点的指针等数据域,占用区链节点有起始地址,大小,作业名和指向下一节点的指针等数据域,本实验用最坏适应算法,每次作业申请内存都是从空闲链队头节点分配,如果相等,就删除空闲头结点,如果小于申请的,就不分配,否则就划分内存给作业,剩下的内存大小,重新插入空闲链队,按从大到小,接着把作业占用的内存放到占用区链节点的末尾。每次作业运行完,就要回收其占用的内存大小,把作业节点按从大到小插入到空闲链队中。 5.源代码: #include #include structfreelinkNode{ intlen; intaddress;

structfreelinkNode*next; };

structbusylinkNode{ charname; intlen; intaddress;

structbusylinkNode*next;

};

structfreelinkNode*free_head=NULL;//自由链队列(带头结点)队首指针

structbusylinkNode*busy_head=NULL;//占用区队列队(带头结点)首指针

structbusylinkNode*busy_tail=NULL;//占用区队列队尾指针 voidstart(void)/*设置系统初始状态*/ {

structfreelinkNode*p;

structbusylinkNode*q;

free_head=(structfreelinkNode*)malloc(sizeof(structfreelinkNode));

free_head->next=NULL;//创建自由链头结点

busy_head=busy_tail=(structbusylinkNode*)malloc(sizeof(structbusylinkNode));

busy_head->next=NULL;//创建占用链头结点

p=(structfreelinkNode*)malloc(sizeof(structfreelinkNode)); p->address=64;

p->len=640-64;//OS占用了64K p->next=NULL; free_head->next=p;

q=(structbusylinkNode*)malloc(sizeof(structbusylinkNode));

q->name='S';/*S表示操作系统占用*/ q->len=64;q->address=0;q->next=NULL; busy_head->next=q;busy_tail=q; }

voidrequireMemo(charname,intrequire)/*模拟内存分配*/ {

p=(structbusylinkNode*)malloc(sizeof(structbusylinkNode)); freelinkNode*w,*u,*v; busylinkNode*p;

if(free_head->next->len>=require) {

p->name=name;

p->address=free_head->next->address; p->len=require;

p->next=NULL;

busy_tail->next=p;

} else

printf(\ busy_tail=p;

w=free_head->next;

free_head->next=w->next; if(w->len==require) {

} else {

w->address=w->address+require; free(w);

w->len=w->len-require;

}

u=free_head; v=free_head->next;

while((v!=NULL)&&(v->len>w->len))

{u=v; }

u->next=w;

v=v->next;

w->next=v; }

voidfreeMemo(charname)/*模拟内存回收*/ {

intlen;