已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
成绩计算机操作系统实验模拟比较页面置换页算法及缺页率学 号200510020220姓 名乔 峰班 级信息052实验名称: 模拟比较页面置换页算法及缺页率实验目的: (1)掌握先进先出页面置换算法;(2)掌握最近未用页面置换算法;(3)了解最近最久未使用页面置换算法以及其他页面置换算法;(4)熟悉C/C+编程。实验学时: 6学时 实验内容: 编写程序,设置不同的页面数,使用不同的页面替换策略算法进行模拟页面替换。先进先出,最近未用页面置换算法等,并计算缺页率。实验环境:(1)PC微机(2)Windows 操作系统(3)C/C+开发环境实验原理及算法参考程序段:#include #include #include #include #include int add256/*地址*/,page256/*页面*/;int k,j,ram,t;float rate;/*缺页率*/struct s1 int page; int free; int tag; fifo33,opt33,lru33;struct s2 int time;void address();float FIFO(int ram);/*先进先出*/float LRU(int ram);/*最近最久未使用页面置换*/void address() /*产生指令地址*/ int i; add0=1000; for (i=1; i=0)&(x=512)&(x=768)&(x1024) addi=addi-1+random(30*1024-addi-1-1)+1; float FIFO(int ram) int absent=0,t=0,i,z,l,yn; for (i=0; iram; i+) fifoi.page=-1; fifoi.free=1; fifoi.tag=0; i=0; while (ij) yn=0; for (z=0; zram; z+) /*the page is in the ram?*/if (fifoz.page=pagei) yn=1; for (z=0; zram; z+) if (fifoz.free=0) fifoz.tag+=1; if (yn!=1) absent+=1; /*count the absent page*/ l=0; while (lram)&(fifol.free=0) l+; if (lram)&(fifol.free=1) /*any free ram?*/ fifol.page=pagei; fifol.free=0; for (l=0; lram; l+) if (fifol.free=0 ) fifol.tag+=1; else /*there is no free ram*/ t=0; for (l=0; lram; l+)if ( fifol.tagfifot.tag) t=l; fifot.page=pagei; fifot.free=0; fifot.tag=1; l=0; i+; rate=(float)absent/j*100; return rate;float LRU(int ram) int absent=0,yn,t,i,l,z,now=0; struct s2 P250; for (i=0;ij;i+) Pi.time=0; for (i=0; iram; i+) lrui.page=-1; lrui.free=1; i=0; while(ij) for(l=0; lram; l+) yn=0; for(z=0; zram; z+) if (lruz.page=pagei) now+=1; Plruz.page.time=now; yn=1; if (yn!=1) absent+=1; now+=1; l=0; while (l=ram)&(lrul.free=0) l+; if (l=ram)&(lrul.free=1) /*any free ram?*/ lrul.page=pagei; Plrul.page.time=now; lrul.free=0; else /*there is no ram*/ t=0; for (l=0; lram; l+) if ( Plrul.page.timePlrut.page.time) t=l; lrut.page=pagei; Plrut.page.time=now; i+; rate=(float)absent/j*100; return rate;void main() int i,p256;/*页号*/ clrscr(); address(); for (k=1; k=8;) /*页面大小: 1k,2k,4k,8K*/ printf(the size of a page is %d kn ,k); printf(the page num is .n); for (i=0; i256; i+) pi=addi/(k*1024);/*将指令地址生成相应的页号*/ printf(%d ,pi); j=0; for (i=0; i256; i+) while (pi=pi+1) i+; pagej=pi; j+; printf(nafter connect the same pages the page num is:n); for (i=0; ij; i+) printf(%d ,pagei); printf(n); getch(); for (ram=1; ramhead-nextpage;/当前页struct page * replacedpage;/要淘汰的页/在当前页中寻找要访问的页号while(currentpage¤tpage-number!=accesspage)currentpage=currentpage-nextpage;/找到页号则打印,并返回0if(currentpage!=NULL¤tpage-number=accesspage)printf();return 0;/没找到则判断页表是否已经满了,没满则调入新页并打印返回1else if(pt-pagenumpagetablesize)newpage=(struct page *)malloc(sizeof(struct page);newpage-number=accesspage;newpage-nextpage=newpage-priorpage=NULL;newpage-nextpage=pt-head-nextpage;if(pt-head-nextpage)pt-head-nextpage -priorpage=newpage;pt-head-nextpage=newpage;newpage-priorpage=pt-head;pt-pagenum+;printf();return 1;/如页表已经满,则采用fifo算法进行淘汰选择elsecurrentpage=pt-head-nextpage;replacedpage=NULL;while(currentpage-nextpage)currentpage=currentpage-nextpage;replacedpage=currentpage;if(replacedpage-nextpage)replacedpage-nextpage-priorpage=replacedpage-priorpage;replacedpage-priorpage-nextpage=replacedpage-nextpage;free(replacedpage);newpage=(struct page *)malloc(sizeof(struct page);newpage-number=accesspage;newpage-nextpage=newpage-priorpage=NULL;newpage-nextpage=pt-head-nextpage; if(pt-head-nextpage)pt-head-nextpage-priorpage=newpage;pt-head-nextpage=newpage;newpage-priorpage=pt-head;printf();return 1;main()struct pagetable pt;unsigned int totalabsence=0,totalpagenum=10;unsigned int restpage100;unsigned int i=0;pt.pagenum=0;pt.pagetablesize=3;pt.head=(struct page*)malloc(sizeof(struct page);pt.head-nextpage=pt.head-priorpage=NULL;/从文件获取要读入的页面流FILE *fp;fp=fopen(IN.dat,r);if(fp=NULL)printf(can not open file IN.DAT!);return;while(!feof(fp)fscanf(fp,%d,&restpagei);i+;fclose(fp);totalpagenum=i;printf(this program for fifo nn);/打印要访问的页for(i=0;itotalpagenum;i+)printf(%2d,restpagei);printf(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 保洁绿化管理员工作管理方法
- 六安市公费师范生招聘真题2025
- 养老服务行业市场调研报告
- ERP运维专员运维数据统计分析
- BIM工程师施工模拟方案
- 产品运营数据分析报告与建议
- 奇瑞销售团队管理与领导力提升策略
- 2026-2031中国硅橡胶行业深度调研研究报告
- 2026-2031中国耕作机器人市场发展规划及投资战略可行性预测报告
- 2025年及未来5年中国胶印油墨市场全面调研及行业投资潜力预测报告
- 【2025年】浙江省湖州市【辅警协警】笔试真题含答案
- 老年肿瘤护理与风险防范
- 图木舒克市供热管理办法
- 安全生产标准化全套档案
- 2025至2030中国航空座椅行业产业运行态势及投资规划深度研究报告
- 2024咳嗽基层诊疗与管理指南
- 公司后勤安全培训课件
- 2025年4月自考00840第二外语(日语)试题
- 新生儿复苏操作规范
- 2025年上海市松江区高考英语一模试卷
- 时空量子化研究-洞察阐释
评论
0/150
提交评论