南京邮电大学实验报告模版_第1页
南京邮电大学实验报告模版_第2页
南京邮电大学实验报告模版_第3页
南京邮电大学实验报告模版_第4页
南京邮电大学实验报告模版_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、实 验 报 告(2014 / 2015 学年 第 一 学期)课程名称计算机操作系统实验名称虚拟存储中页面置换算法的模拟实现实验时间2014年12月19日指导单位南京邮电大学指导教师崔衍学生姓名班级学号学院(系)物联网院专 业网络工程- 18 - / 18文档可自由编辑打印实 验 报 告实验名称虚拟存储中页面置换算法的模拟实现指导教师崔衍实验类型上机实验实验学时4实验时间2014.12.19一、 实验目的和要求目的:通过请求页式存储管理中页面置换算法模拟设计,了解虚拟存储技术的技术特点,掌握请求页式存储管理的页面置换算法要求:(1)设计实现下面算法,并输出下述各种算法的命中率。 先进先出的算法(

2、FIFO); 最近最少使用算法(LRR); 最佳淘汰算法(OPT)先淘汰最不常用的页地址。(2)多次反复运行改进后的程序,观察并记录运行结果,并分析原因。二、实验环境(实验设备)Vc+6.0二、 实验原理及内容实验三#include <iostream.h>#include<stdlib.h>#include<conio.h>#include<stdio.h>#define Bsize 4typedef struct BLOCK/声明一种新类型物理块类型 int pagenum;/页号 int accessed;/访问字段,其值表示多久未被访问B

3、LOCK; int pc;/程序计数器,用来记录指令的序号int n;/缺页计数器,用来记录缺页的次数 static int temp320;/用来存储320条随机数BLOCK blockBsize; /定义一大小为4的物理块数组/*void init( ); /程序初始化函数int findExist(int curpage);/查找物理块中是否有该页面int findSpace( );/查找是否有空闲物理块int findReplace( );/查找应予置换的页面void display ( );/显示void suijishu( );/产生320条随机数,显示并存储到temp320voi

4、d pagestring( );/显示调用的页面队列void OPT( );/OPT算法void LRU( );/ LRU算法void FIFO( );/FIFO算法/*void init( ) for(int i=0;i<Bsize;i+) blocki.pagenum=-1; blocki.accessed=0; pc=n=0; /-int findExist(int curpage) for(int i=0; i<Bsize; i+) if(blocki.pagenum = curpage ) return i;/检测到内存中有该页面,返回block中的位置 return -

5、1;/-int findSpace( ) for(int i=0; i<Bsize; i+) if(blocki.pagenum = -1) return i;/找到空闲的block,返回block中的位置 return -1;/-int findReplace( ) int pos = 0; for(int i=0; i<Bsize; i+) if(blocki.accessed >blockpos.accessed) pos = i;/找到应予置换页面,返回BLOCK中位置 return pos;/-void display( ) for(int i=0; i<Bs

6、ize; i+) if(blocki.pagenum != -1) printf(" %02d",blocki.pagenum); cout<<endl;/-void suijishu( ) int flag=0; cin>>pc; cout<<"*按照要求产生的320个随机数:*"<<endl; for(int i=0;i<320;i+) tempi=pc; if(flag%2=0) pc=+pc%320; if(flag=1) pc=rand( )% (pc-1); if(flag=3) pc=p

7、c+1+(rand( )%(320-(pc+1); flag=+flag%4; printf(" %03d",tempi); if(i+1)%10=0) cout<<endl; /-void pagestring( ) for(int i=0;i<320;i+) printf(" %02d",tempi/10); if(i+1)%10=0) cout<<endl; /-void OPT( ) int exist,space,position ; int curpage; for(int i=0;i<320;i+) if

8、(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace ( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else for(int k=0;k<Bsize;k+) for(int j=i;j<320;j+) if(blockk.pagenum!= tempj/10) blockk.accessed = 1000; /将来不会用,设置为一个很大数

9、 else blockk.accessed = j; break; position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; cout<<"缺页次数:"<<n<<endl; cout<<"缺页率:"<<(n/320.0)*100<<"%"<<endl;/- void LRU( ) int exist,space,position ; int curpage;

10、for(int i=0;i<320;i+) if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; else blockexist.acc

11、essed = -1;/恢复存在的并刚访问过的BLOCK中页面accessed为-1 for(int j=0; j<4; j+) blockj.accessed+; cout<<"缺页次数:"<<n<<endl; cout<<"缺页率:"<<(n/320.0)*100<<"%"<<endl;/-void FIFO( ) int exist,space,position ; int curpage; for(int i=0;i<320;i+)

12、 if(i%100=0) getch( ); pc=tempi; curpage=pc/10; exist = findExist(curpage); if(exist=-1) space = findSpace( ); if(space != -1) blockspace.pagenum = curpage; display( ); n=n+1; else position = findReplace( ); blockposition.pagenum = curpage; display( ); n+; blockposition.accessed-; for(int j=0; j<

13、Bsize; j+) blockj.accessed+; cout<<"缺页次数:"<<n<<endl; cout<<"缺页率:"<<(n/320.0)*100<<"%"<<endl;/*void main( ) int select; cout<<"请输入第一条指令号(0320):" suijishu( ); cout<<"*对应的调用页面队列*"<<endl; pagest

14、ring( ); do cout<<"*"<<endl; cout<<"-1:OPT 2:LRU 3:FIFO 4:退出-"<<endl; cout<<"*"<<endl; cout<<" 请选择一种页面置换算法:" cin>>select; cout<<"*"<<endl; init( ); switch(select) case 1:cout<<"最佳

15、置换算法OPT:"<<endl; cout<<"*"<<endl; OPT( ); break; case 2:cout<<"最近最久未使用置换算法LRU:"<<endl; cout<<"*"<<endl; LRU( ); break; case 3:cout<<"先进先出置换算法FIFO:"<<endl; cout<<"*"<<endl; FIFO( )

16、; break; default: ; while(select!=4);实验结果: 实验四Login用户登录bool chklogin(char *users, char *pwd)int i;for(i=0; i<8; i+)if( (strcmp(users,)=0) && (strcmp(pwd,usrarrayi.pwd)=0)return true;return false;Create创建文件int create()temp=initfile(" ",0);cin>>temp->cin>

17、>temp->content;if(recent->child=NULL)temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;cout<<"文件建立成功!"<<endl;elsettemp=recent->child;while(ttemp->next)ttemp=ttemp->next;if(strcmp(ttemp->>)=0&&ttemp-

18、>isdir=0)printf("对不起,文件已存在!");return 1;ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;cout<<"文件建立成功!"<<endl;return 1;int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout<<" <DIR> &q

19、uot;<<"."<<endl;i+;if(temp->child=NULL)cout<<"Total: "<<" directors" <<i<<" files"<< j <<endl;return 1;temp=temp->child;while(temp)if(temp->isdir)cout<<"<DIR> "<<temp-><

20、<endl;i+;elsecout<<"<FILE> "<<temp-><<endl;j+;temp=temp->next;cout<<"Total: "<<" directors" <<i<<"files"<< j <<endl;Read读取文件int read()char ;cin>>if(recent->child=NULL)cout<<&qu

21、ot;文件不存在!"<<endl;return 1;if(strcmp(recent->child->)=0)cout<<recent->child->content<<endl;return 1;elsetemp=recent->child;while(temp->next)if(strcmp(temp->next->)=0)cout<<temp->next->content<<endl;return 1;cout<<"文件不存在!"

22、;<<endl;Write写入文件int write()char ;cin>>if(recent->child=NULL)cout<<"文件不存在!"<<endl;return 1;if(strcmp(recent->child->)=0)recent->child->isopen=1;/设置文件标记为打开cin>>recent->child->content;recent->child->isopen=0;/设置文件标记为关闭cout<<"

23、;文件写入成功!"<<endl;return 1;elsetemp=recent->child;while(temp->next)if(strcmp(temp->next->)=0)recent->child->isopen=1;/设置文件标记为打开cin>>temp->next->content;recent->child->isopen=0;/设置文件标记为关闭cout<<"文件写入成功!"<<endl;return 1;cout<<&quo

24、t;文件不存在!"<<endl;Del删除int del()char ;cin>>temp=new fnode;if(recent->child)temp=recent->child;while(temp->next && (strcmp(temp->)!=0 | temp->isdir!=0)temp=temp->next;if(strcmp(temp->)!=0)cout<<"不存在该文件!"<<endl;return 0;elsecout<<

25、"不存在该文件!"<<endl;return 0;if(temp->parent=NULL)temp->prev->next=temp->next;if(temp->next)temp->next->prev=temp->prev;temp->prev=temp->next=NULL;elseif(temp->next)temp->next->parent=temp->parent;temp->parent->child=temp->next;delete te

26、mp;cout<<"文件已删除!"<<endl;建立目录int mkdir()temp=initfile(" ",1);cin>>temp->if(recent->child=NULL)temp->parent=recent;temp->child=NULL;recent->child=temp;temp->prev=temp->next=NULL;elsettemp=recent->child;while(ttemp->next)ttemp=ttemp->n

27、ext;if(strcmp(ttemp->>)=0&&ttemp->isdir=1)printf("对不起,目录已存在!");return 1;ttemp->next=temp;temp->parent=NULL;temp->child=NULL;temp->prev=ttemp;temp->next=NULL;return 1;切换目录int dir()int i=0,j=0;temp=new fnode;temp=recent;if(temp!=root)cout<<" <DIR> "<<"."<<endl;i+;if(temp->child=NULL)cout<<"Total: "<<" directors" <<i<<" files"<< j <<endl;return 1;temp=temp->child;while(temp)if(temp->isdir)cout<<"<D

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论