实验四 Paging Memory Management(分页式存储管理)
一、实验名称
Paging Memory Management(分页式存储管理) 二、实验目的
理解分页式存储管理的原理。 三、实验内容
在分页系统中,把每个作业(进程)的地址空间划分成一些大小相等的片,称之为页面或页。同样地,把内存的存储空间也分成与页相同大小的存储块,称为物理块或页框。分页系统允许将进程的每一页离散地存储在内存的任一物理块中,为了能在内存中找到每个页面所对应的物理块,系统为每个进程建立一张页面映射表,即页表,图1所示。页表的作用是实现从页号到物理块号的地址映射。
四、实验要求
模拟多个作业分页式存储管理的全过程。 五、实验学时及环境
4学时,Turbo C、Visual C++、Visual Basic、Delphi均可。 六、实验思路
1.划分出一块内存空间,并为其编号;
2.初始化若干个作业,并为每个作业随机分配物理块号,每个作业包括标识号、页数、运行时间和物理块号四部分;
3.随着时间的推移,描述每个作业的开始、运行与结束过程; 4.在每个时间点,随机产生若干个新的作业。 七、主要程序代码
如果使用C语言进行设计,程序涉及的头文件主要有:stdio.h, dos.h, time.h, conio.h。
以下是用C语言开发的代码示例:
#include
struct page {char ch; int count; int page[4]; int tim; }aa[100]; int num=0;
struct mem {int x; int ch; }frame[30]; int a=48; int sum=0;
void first() {int i;
for(i=0;i<30;i++) {frame[i].ch=0; frame[i].x=0;
} }
void ttim() {struct time t; gettime(&t);
printf(\ .ti_sec); } num0_1() {int i; i=rand()0; if(frame[i].x==1) num0_1(); else return i; }
void fenpei() {int i;
aa[num].ch=a; a++; if(a==58) a=65; if(a==91) a=97;
aa[num].tim=rand()%4+5; aa[num].count=rand()%4+1; for(i=0;i
frame[aa[num].page[i]].ch=aa[num].ch; }
-:d:d\\n\ }
void check() {int i,j;
for(i=0;i for(j=0;j frame[aa[i].page[j]].ch=0; } } } void putout() {int i,j; printf(\ \ for(i=0;i<30;i++) {printf(\ if(i==14) printf(\ \ } for(i=0;i<=14;i++) {window(11+i*4,5,12+i*4,5); if(frame[i].x==1) textbackground(RED); else textbackground(GREEN); clrscr(); cprintf(\ } for(i=0;i<=14;i++) {window(11+i*4,8,12+4*i,8); if(frame[i+15].x==1) textbackground(RED); else textbackground(GREEN); clrscr(); cprintf(\ } window(25,10,55,23); textbackground(8); clrscr(); printf(\ Size Time Mem\ window(25,11,55,23); textbackground(6); clrscr(); sum=0; for(i=0;i {printf(\ printf(\ \ for(j=0;j printf(\ printf(\ \ sum++; } } } void work() {int cishu=60; int k; int i; while(cishu--) {clrscr(); window(1,1,80,25); textbackground(BLUE); clrscr(); textcolor(YELLOW); clrscr(); ttim(); k=rand()%2; if(k==1) {k=rand()%3+1; if((sum+k)>13) k=0; for(i=0;i num++; } } check(); putout(); sleep(1); } } main() {time_t t; srand((unsigned) time(&t)); clrscr(); first(); work(); window(1,1,80,25); textbackground(BLUE); clrscr(); printf(\ getch(); } Press Any Key to Exit !\