东北大学 操作系统实验五报告.docx
- 文档编号:3978452
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:9
- 大小:145.93KB
东北大学 操作系统实验五报告.docx
《东北大学 操作系统实验五报告.docx》由会员分享,可在线阅读,更多相关《东北大学 操作系统实验五报告.docx(9页珍藏版)》请在冰豆网上搜索。
东北大学操作系统实验五报告
操作系统实验报告
班级
物联网1302班
学号
姓名
实验5页面置换算法
1、实验题目:
页面置换算法(请求分页)
2、实验目的:
进一步理解父子进程之间的关系。
1)理解内存页面调度的机理。
2)掌握页面置换算法的实现方法。
3)通过实验比较不同调度算法的优劣。
4)培养综合运用所学知识的能力。
页面置换算法是虚拟存储管理实现的关键,通过本次试验理解内存页面调度的机制,在模拟实现FIFO、LRU等经典页面置换算法的基础上,比较各种置换算法的效率及优缺点,从而了解虚拟存储实现的过程。
将不同的置换算法放在不同的子进程中加以模拟,培养综合运用所学知识的能力。
3、实验内容及要求
这是一个综合型实验,要求在掌握父子进程并发执行机制和内存页面置换算法的基础上,能综合运用这两方面的知识,自行编制程序。
程序涉及一个父进程和两个子进程。
父进程使用rand()函数随机产生若干随机数,经过处理后,存于一数组Acess_Series[]中,作为内存页面访问的序列。
两个子进程根据这个访问序列,分别采用FIFO和LRU两种不同的页面置换算法对内存页面进行调度。
要求:
1)每个子进程应能反映出页面置换的过程,并统计页面置换算法的命中或缺页情况。
设缺页的次数为diseffect。
总的页面访问次数为total_instruction。
缺页率=disaffect/total_instruction
命中率=1-disaffect/total_instruction
2)将为进程分配的内存页面数mframe作为程序的参数,通过多次运行程序,说明FIFO算法存在的Belady现象。
四、程序流程图
5、程序源代码、文档注释及文字说明
#include
#include
#include
#include
#include
#include
#include
#include
#definetotal_instruction12
voidmain()
{
intn,m;
voidLRU(intAcess_series[]);
voidFIFO(intAcess_series[]);
srand((int)time(NULL));
intAcess_series[total_instruction]/*={4,1,1,2,4,4,3,4,2,5,2,1}*/;
for(inti=0;i Acess_series[i]=(int)(rand()/3276.7)%5+1; printf("therandnumber: \n"); for(inti=0;i printf("%d",Acess_series[i]); printf("\n"); //LRU(Acess_series); //FIFO(Acess_series); intx,y,fd[2]; if((x=fork())==0) { if((y=fork())==0)LRU(Acess_series); elseFIFO(Acess_series); } else; } voidLRU(intAcess_series[]){ intM_Frame[3]; intM[3],diseffect=0,top=0; for(inti=0;i<3;i++){M_Frame[i]=0;M[i]=0;} printf("\nusingLRU: \n"); for(inti=0;i { if(top==0){M_Frame[0]=Acess_series[i];diseffect++;top++;} elseif(top==1){ if(M_Frame[0]==Acess_series[i])M[0]=-1; else{M_Frame[1]=Acess_series[i];diseffect++;top++;} } elseif(top==2){ if(M_Frame[0]==Acess_series[i]) { M_Frame[0]=M_Frame[1];M_Frame[1]=Acess_series[i];M[0]=-1; } elseif(M_Frame[1]==Acess_series[i])M[1]=-1; else{M_Frame[2]=Acess_series[i];diseffect++;top++;} } else{ if(M_Frame[0]==Acess_series[i]) { M_Frame[0]=M_Frame[1];M_Frame[1]=M_Frame[2];M_Frame[2]=Acess_series[i]; M[0]=-1; } elseif(M_Frame[1]==Acess_series[i]) { M_Frame[1]=M_Frame[2];M_Frame[2]=Acess_series[i]; M[1]=-1; } elseif(M_Frame[2]==Acess_series[i])M[2]=-1; else { M_Frame[0]=M_Frame[1];M_Frame[1]=M_Frame[2];M_Frame[2]=Acess_series[i]; diseffect++; } } for(intj=0;j<3;j++) { printf("%d",M_Frame[j]); M[j]++; } if(M[0]&&M[1]&&M[2])printf("notarget"); elseprintf("target"); printf("\n"); } printf("thenumberoftarget: %d",total_instruction-diseffect); } voidFIFO(intAcess_series[]){ intM_Frame[3]; intM=0,diseffect=0,top=0; for(inti=0;i<3;i++)M_Frame[i]=0; printf("\nusingFIFO: \n"); for(inti=0;i { if(top==0){M_Frame[0]=Acess_series[i];diseffect++;top++;} elseif(top==1){ if(M_Frame[0]! =Acess_series[i]){M_Frame[1]=Acess_series[i];diseffect++;top++;} elseM=1; } elseif(top==2){ if(M_Frame[0]==Acess_series[i]||M_Frame[1]==Acess_series[i])M=1; else{M_Frame[2]=Acess_series[i];diseffect++;top++;} } else{ if(M_Frame[0]==Acess_series[i]||M_Frame[1]==Acess_series[i]||M_Frame[2]==Acess_series[i])M=1; else{ M_Frame[0]=M_Frame[1];M_Frame[1]=M_Frame[2];M_Frame[2]=Acess_series[i]; diseffect++; } } for(intj=0;j<3;j++) printf("%d",M_Frame[j]); if(M==1){ printf("target");M=0; } elseprintf("notarget"); printf("\n"); } printf("thenumberoftarget: %d",total_instruction-diseffect); } 6、运行结果及其说明 七、回答以下问题: ①父进程、子进程之间的并发执行的过程 父子进程之间的调度基于调度算法调度到CPU中运行,从宏观上来看就是并发执行 ②通过完成实验,根据你的体会,阐述虚拟存储器的原理。 为解决内存小而作业大、作业多的矛盾,以及执行过程中只是把当前运行需要的那部分程序和数据装入内存。 所以,操作系统把各级存储器统一管理起来。 就是说,应该把一个程序当前正在使用的部分放在内存,而其余部分放在磁盘上,就启动执行它。 操作系统根据程序执行时的要求和内存的实际使用情况,随机地对每个程序进行换入/换出。 ③写出FIFO算法中出现Belady现象的内存页面访问序列。 当内存块大小分别为3和4时,访问顺序为1,2,3,4,1,2,5,1,2,3,4,5时会出现Belady现象。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 东北大学 操作系统实验五报告 操作系统 实验 报告
![提示](https://static.bdocx.com/images/bang_tan.gif)