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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

虚拟存储器管理方案实验报告.docx

1、虚拟存储器管理方案实验报告淮海工学院计算机科学系实验报告书课程名: 操 作 系 统 题 目: 虚拟存储器管理 页面置换算法模拟实验 班 级: 学 号: 姓 名: 一、实验目的与要求1. 目的:请求页式虚存管理是常用的虚拟存储管理方案之一。通过请求页式虚存管理中对页面置换算法的模拟,有助于理解虚拟存储技术的特点,并加深对请求页式虚存管理的页面调度算法的理解。2. 要求:本实验要求使用C语言编程模拟一个拥有若干个虚页的进程在给定的若干个实页中运行、并在缺页中断发生时分别使用FIFO和LRU算法进行页面置换的情形。其中虚页的个数可以事先给定(例如10个),对这些虚页访问的页地址流(其长度可以事先给定

2、,例如20次虚页访问)可以由程序随机产生,也可以事先保存在文件中。要求程序运行时屏幕能显示出置换过程中的状态信息并输出访问结束时的页面命中率。程序应允许通过为该进程分配不同的实页数,来比较两种置换算法的稳定性。二、实验说明 1设计中虚页和实页的表示本设计利用C语言的结构体来描述虚页和实页的结构。pnpfntimepnpfnnext 虚页结构 实页结构在虚页结构中,pn代表虚页号,因为共10个虚页,所以pn的取值范围是09。pfn代表实页号,当一虚页未装入实页时,此项值为-1;当该虚页已装入某一实页时,此项值为所装入的实页的实页号pfn。time项在FIFO算法中不使用,在LRU中用来存放对该虚

3、页的最近访问时间。在实页结构中中,pn代表虚页号,表示pn所代表的虚页目前正放在此实页中。pfn代表实页号,取值范围(0n-1)由动态指派的实页数n所决定。next是一个指向实页结构体的指针,用于多个实页以链表形式组织起来,关于实页链表的组织详见下面第4点。2关于缺页次数的统计为计算命中率,需要统计在20次的虚页访问中命中的次数。为此,程序应设置一个计数器count,来统计虚页命中发生的次数。每当所访问的虚页的pfn项值不为-1,表示此虚页已被装入某实页内,此虚页被命中,count加1。最终命中率=count/20*100%。3LRU算法中“最近最久未用”页面的确定为了能找到“最近最久未用”的

4、虚页面,程序中可引入一个时间计数器countime,每当要访问一个虚页面时,countime的值加1,然后将所要访问的虚页的time项值设置为增值后的当前countime值,表示该虚页的最后一次被访问时间。当LRU算法需要置换时,从所有已分配实页的虚页中找出time值为最小的虚页就是“最近最久未用”的虚页面,应该将它置换出去。4算法中实页的组织因为能分配的实页数n是在程序运行时由用户动态指派的,所以应使用链表组织动态产生的多个实页。为了调度算法实现的方便,可以考虑引入free和busy两个链表:free链表用于组织未分配出去的实页,首指针为free_head,初始时n个实页都处于free链表中

5、;busy链表用于组织已分配出去的实页,首指针为busy_head,尾指针为busy_tail,初始值都为null。当所要访问的一个虚页不在实页中时,将产生缺页中断。此时若free链表不为空,就取下链表首指针所指的实页,并分配给该虚页。若free链表为空,则说明n个实页已全部分配出去,此时应进行页面置换:对于FIFO算法要将busy_head 所指的实页从busy链表中取下,分配给该虚页,然后再将该实页插入到busy链表尾部;对于LRU算法则要从所有已分配实页的虚页中找出time值为最小的虚页,将该虚页从装载它的那个实页中置换出去,并在该实页中装入当前正要访问的虚页。三、程序流程图三个模块的流

6、程图1登录模块开 始打开w_input窗口关闭w_main窗口点击确定按钮是否点击取消按钮是2参数输入模块开 始打开w_accept窗口关闭w_input窗口点击确定按钮是否点击取消按钮输入了磁头位置是否输入当前磁头位置输入了各磁道号是否输入各磁道号位置确定输入这些数是是否3算法实现模块四、主要程序清单模块之间的调用关系登录模块参数输入模块点击确定按钮算法实现模块点击确定按钮点击返回按钮 #include#include#includeint producerand(int remainder);void initprocess();void chosedisplace();struct li

7、nknode * fifo(struct linknode *head,int randcount);void Optimal(struct linknode*head,int randprocess);struct linknode* LRU(struct linknode *head,int randprocess);struct linknode* initlink();void choicestey();int allotment(struct linknode *head);bool checkfifooptimal(struct linknode* head,int checkpa

8、ge);void recover(struct linknode *head,int randprocess);void recovermemory(); int process1020;/数组的横坐标为进程序列,纵坐标为每个进程的页号 int processallotment6;/存储每个进程已经分配的块数 int finishp6;/标志进程是否完成(1完成0不完成) int finishprocess=0;/进程完成的个数 int findpage6;/每个进程命中的个数 struct linknode *plinkhead6;struct linknode *plink6;int me

9、moryallotment6; int stey=0;struct linknode struct linknode *linkper;/空链表的前驱指针 int page; int processpage; int used; int memorypage; struct linknode *linknext;/空链表的后继指针 struct linknode *processper;/进程的前去指针 struct linknode *processnext;/进程的后继指针 ;int main() struct linknode *head=initlink(); initprocess(

10、); choicestey(); int re=allotment(head); if(re=0) printf(内存分配出现问题。);system(pause); chosedisplace(); recovermemory(); system(pause);void recovermemory() int n=0; printf(是否回收全部已分配的内存空间?n回收输入 1,不回收输入2n); scanf(%d,&n); if(n=1) for(int i=1;iused=0; head=head-processnext; void choicestey() printf(请选择置换算法n

11、); printf(1 表示FIFOn2 表示Optimaln3 表示LRUn); bool flag=true; while(flag) scanf(%d,&stey); switch(stey) case 1:printf(您选择的是FIFO替换算法n);flag=false; break; case 2:printf(您选择的是Optimal替换算法n);flag=false;break; case 3:printf(您选择的是LRU替换算法n);flag=false;break; default :printf(输入错误,请重新输入n); void chosedisplace()/选择

12、置换算法 struct linknode *head; int randcount;/进程序号 bool find; while(finishprocess5) randcount=producerand(5); while(processallotmentrandcountprocessrandcount0) find=false; head=plinkheadrandcount; if(stey=1|stey=2) find=checkfifooptimal(head,processrandcountprocessallotmentrandcount+1); if(find=true) f

13、indpagerandcount+; if(find=false)/如果在链表中没找到当前的页数 switch(stey) case 1: plinkheadrandcount=fifo(plinkheadrandcount,randcount); break; case 2: Optimal(plinkheadrandcount,randcount); break; case 3: plinkheadrandcount=LRU(plinkheadrandcount,randcount); break; processallotmentrandcount+; if(finishprandcou

14、nt=0) finishprocess+; finishprandcount=1; struct linknode *p; printf(进程执行完后内存分配情况:n); for(int i=1;imemorypage,p-processpage,p-page); p=p-processnext; for(int i=1;ipage=checkpage) return true; else head=head-processnext; return false;struct linknode* LRU(struct linknode *head,int randprocess) struct

15、linknode *bhead; bhead=head; while(head-processnext!=0) if(head-page=processrandprocessprocessallotmentrandprocess+1) break; else head=head-processnext; if(head-page!=processrandprocessprocessallotmentrandprocess+1)/没找到 bhead-page=processrandprocessprocessallotmentrandprocess+1; head-processnext=bhe

16、ad; bhead-processper=head; bhead=bhead-processnext; bhead-processper=0; head=head-processnext; head-processnext=0; plinkrandprocess=plinkrandprocess-processnext; return bhead; else/找到了 if(head=bhead)/头 head-processper=plinkrandprocess; plinkrandprocess-processnext=head; plinkrandprocess=plinkrandpro

17、cess-processnext; head=head-processnext; head-processper=0; plinkrandprocess-processnext=0; findpagerandprocess+; return head; else if(head-processnext=0)/尾 findpagerandprocess+; return bhead; else/中间 head-processnext-processper=head-processper; head-processper-processnext=head-processnext; head-pro

18、cessnext=0; head-processper=plinkrandprocess; plinkrandprocess-processnext=head; plinkrandprocess=plinkrandprocess-processnext; findpagerandprocess+; return bhead; void Optimal(struct linknode*head,int randprocess) struct linknode *maxp; maxp=head; int max=1,i; while(head!=0) for(i=processallotmentr

19、andprocess+1;ipage) break; if(imax) max=i; maxp=head; head=head-processnext; maxp-page=processrandprocessprocessallotmentrandprocess+1;struct linknode* fifo(struct linknode*head,int randprocess) struct linknode*phead;/改变后的头指针 phead=head; head-page=processrandprocessprocessallotmentrandprocess+1; whi

20、le(head-processnext!=0) head=head-processnext; head-processnext=phead; phead-processper=head; phead=phead-processnext; head=head-processnext; head-processnext=0; phead-processper=0; return phead;int allotment(struct linknode *head)/为进程分配内存 int allotsum=0;/已经分配完进程的个数 int randprocess;/当前要分配内存的进程标号 boo

21、l boolallot6; for(int i=1;i6;i+) processallotmenti=0; boolalloti=false; memoryallotmenti=0; while(allotsumused=0) if(processallotmentrandprocess=0) plinkheadrandprocess=head; plinkrandprocess=head; plinkrandprocess-processper=0; plinkrandprocess-processnext=0; head-processpage=randprocess; plinkrand

22、process-page=processrandprocess1; head-used=1; printf(内存块号:%dt进程号:%dt页号:%dn,head-memorypage,head-processpage,head-page); head=head- linknext; memoryallotmentrandprocess+; findpagerandprocess+; else bool checksame=checkfifooptimal(plinkheadrandprocess,processrandprocessprocessallotmentrandprocess+1);

23、 if(checksame=false) head-used=1; head-processnext=0; head-processper=plinkrandprocess; plinkrandprocess- processnext=head; head-processpage=randprocess; head-page=processrandprocessprocessallotmentrandprocess+1; plinkrandprocess=plinkrandprocess-processnext; printf(内存块号:%dt进程号:%dt页号:%dn,head-memory

24、page,head-processpage,head-page); head=head-linknext; memoryallotmentrandprocess+; findpagerandprocess+; else if(stey=3) plinkheadrandprocess=LRU(plinkheadrandprocess,randprocess); else findpagerandprocess+; processallotmentrandprocess+; else printf(进程%d分配失败n,randprocess); return 0; if(head=0) printf(进程%d分配失败n,randprocess); return 0; if(processallotmentrandprocess=processrandprocess0) printf(进程%d分配成功n,randprocess); allotsum+; boolallotrandprocess=true; finishprocess+; finishprandprocess=1; else if(memoryallotmentrandprocess=4) allotsum+; boolallotrandprocess

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

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