计算机操作系统缺页率计算,计算机操作系统实验模拟比较页面置换页算法及缺页率(1)...

a7f4a3f590493a1e451dd952a488fd7c.gif 计算机操作系统实验模拟比较页面置换页算法及缺页率(1)

(10页)

1653c5e0d7d5aacfc8170be8e10d9c66.gif

本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!

19.90 积分

成绩成绩 计算机操作系统实验 模拟比较页面置换页算法及缺页率 学 号200510020220 姓 名乔 峰 班 级信息 052 实验名称实验名称: 模拟比较页面置换页算法及缺页率 实验目的实验目的: (1)掌握先进先出页面置换算法; (2)掌握最近未用页面置换算法; (3)了解最近最久未使用页面置换算法以及其他页面置换算法; (4)熟悉 C/C++编程。 实验学时实验学时: 6 学时 实验内容实验内容: 编写程序,设置不同的页面数,使用不同的页面替换策略算法进行 模拟页面替换。先进先出,最近未用页面置换算法等,并计算缺 页率。 实验环境实验环境: (1).PC 微机 (2).Windows 操作系统 (3).C/C++开发环境 实验原理及算法参考程序段实验原理及算法参考程序段: #include #include #include #include #include int add[256]/*地址*/,page[256]/*页面*/; int k,j,ram,t; float rate;/*缺页率*/ struct s1 { int page; int free; int tag; } fifo[33],opt[33],lru[33]; struct s2 { int time; }; void address(); float FIFO(int ram);/*先进先出*/ float LRU(int ram);/*最近最久未使用页面置换*/ void address() /*产生指令地址*/ { int i; add[0]=1000; for (i=1; i=0)//当前页 struct page * replacedpage;//要淘汰的页 //在当前页中寻找要访问的页号 while(currentpage } //找到页号则打印√,并返回 0 if(currentpage!=NULL return 0; } //没找到则判断页表是否已经满了,没满则调入新页并打印×返回 1 else 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 算法进行淘汰选择 else { currentpage=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 restpage[100]; 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“, i++; } fclose(fp); totalpagenum=i; printf(“this program for fifo \n\n“); //打印要访问的页 for(i=0;itotalpagenum;i++) { printf(“%2d“,restpage[i]); } printf(“\n“); //调用函数访问页 for(i=0;itotalpagenum;i++) { totalabsence+=access( } printf(“\nabsence times:%d\ntotal access times:%d\nabsence ratio:%.2f%%\n“,totalabsence,totalpagenum,totalabsence*100.0/totalpagenum); getchar(); } 关 键 词: 计算机 操作系统 实验 模拟 比较 页面 置换 算法 缺页率

4d91c43bfc72ca913299809b07b4968f.gif  天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

关于本文

本文标题:计算机操作系统实验模拟比较页面置换页算法及缺页率(1)

链接地址: https://www.wenku365.com/p-34066973.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值