《实验一:分页存储管理模拟实验.docx》由会员分享,可在线阅读,更多相关《实验一:分页存储管理模拟实验.docx(4页珍藏版)》请在第一文库网上搜索。
1、实验一:分页存储管理模拟实验1 .实验要求:掌握分页存储管理的基本概念和实现方法。要求编写一个模拟的分页管理程序,能对一个己有的程序实现分页显示。2 .数据结构:(1)数据文件:在磁盘上创建一个包含IooO个数据的文件datatxt.从。开始,每100个数为一页。(2)页面映像表包括:页号、中断位、块号。(3)内存缓冲区:申请存放300个字的缓冲区,设每100个字为一个内存块。初始状态:将数据文件的第一个页面装入到该缓冲区的第0块。(4)页面置换表:页面置换表的表项为3项,一个替换指针。采用先进先出页面置换算法.3 .程序算法:(1)主程序:建立一个用户数据文件,初始化操作系统的数据结构;并装
2、入用户数据文件的第一页。(2)调页程序:当读入数据的逻辑地址对应的块不在内存时,调用调页程序。该程序负责从数据文件中调入所需的页。(3)置换算法:当内存缓冲区中没有空闲块时,依置换策略选择一个可置换的页。4 .源程序#inc1ude#inc1udestructdata(intpage;intb1ock;intf1ag;number10;structrename(intb1ock;intpage;name4;intmain()(FI1E*fp;intcount1,count2,rep1ace=0;intbuffer110100,buffer210100;charnum;fbr(count1=0;
3、count11Ojcount1+)for(count2=0;count2100;count2+)buffer11count1count2=100*count1+count2;if(fp=fopen(Mdata.txt,Mwbu)=NU11)(fprintf(stderr,erroropeningfi1e.);system(pausen);exit(1);)if(fwrite(buffer1,sizeof(int),1000,fp)!=1000)fprintf(stderr,errorwritingfi1eexit(1);)if(fc1ose(fp)=EOF)printf(nc1osefi1ee
4、rror*);exit(1);)printf(uThepage&Theb1ocknu);fr(count1=0;count14;count1+)(if(fp=fopen(data.txt,rb)=NU11)(fprintf(stderr,erroropeningfi1eexit(1);)fseek(fp,100*sizeof(int)*count1,0);if(fread(buffer21count1,sizeof(int),100,fp)!=100)fprintf(stderr,errorwritingfi1e.);exit(1);)if(fc1ose(fp)=EOF)(printf(,nc
5、1osefi1eerror*);exit(1);)printf(%d%dn,count1,count1);1fbr(count1=0;count110;count1+)(if(count14)(numbercount1.page=count1;number1count1.b1ock=count1;number1count1.f1ag=0;)e1senumbercount1.page=count1;number1count1.b1ock=count1;number1count1.f1ag=1;)fbr(count1=0;count14;count1+)namecount1.page=count1
6、;namecount1.b1ock=count1;)whi1e(1)(printf(Inputtheaddress:numberpage(0-9)n);scanf(,%d,fecount1);rintf(Inputtheaddress:department(0-99)nu);scanf(u%d,&count2);if(count19)continue;if(count299)continue;if(numbercount1.f1ag=0)printf(,Theaddress:%dn,buffer2name1count1.b1ock1count2J);e1senumberrep1ace.b1oc
7、k=count1;numberrep1ace.f1ag=1;number1count1.f1ag=0;namerep1ace.b1ock=rep1ace;if(fp=fopen(data.txt,rb)=NU11)(fprintf(stderr,erroropeningfi1e.);exit(1);)fseek(fp,100*sizeof(int)*count1,0);if(fread(buffer2(rep1ace,sizeof(int),1OO,fp)!=100)(fprintf(stderr,errorwritingfi1eexit(1);)if(fc1ose(fp)=EOF)(prin
8、tf(,nc1osefi1eerror);exit(1);)printf(Theaddress:%dnu,buffer2rep1acecount2);rep1ace=(rep1ace+1)%4;)printf(Thepage&Theb1ockn);fbr(count1=0;count14jcount1+)printfC,%d%dn,count1,numbercount1.b1ock);)return0;)5 .实验结果b0123Iob5123b5723Iob5743b5749Thepage&The0123Inputtheaddress5Inputtheaddress:43Theaddress:543hepage&The0123Inputtheaddress7Inputtheaddress:26Theaddress:726Thepage&The0123Inputtheaddress4Inputtheaddress:11Theaddress:411hepage&The0123Inputtheaddress9Inputtheaddress:3eaddress:903Thepage&The0123numberpagedepartmentpagedepartmentpagedepartment:numberpagedepartment0-99)