【发布时间】:2015-05-30 15:55:53
【问题描述】:
我正在C 中进行操作系统Memory Management Paging Scheme 模拟,所以这是我目前所做的:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int alloc[50], base[50], frame[50], job[50];
int i, n, pa, fs, ps, nf, temp;
clrscr();
printf("\n\t\t PAGING\n");
printf("\n\t Enter the physical address space:");
scanf("%d",&pa);
printf("\n\t Enter the page size:");
scanf("%d",&ps);
nf=pa/ps;
printf("\n\t Number of frames = %d",nf);
for(i=0;i<nf;i++)
{
alloc[i]=0;
printf("Enter job number %d",i+1);
scanf("%d",job[i]);
if ( // If job can fit ) {
// Here job will fit one by one
temp=rand()%nf;
while( alloc[temp] == 1 )
temp=rand()%nf;
alloc[temp]=1;
frame[i]=temp;
// The main algo will come here
base[i]=frame[i]*ps;
printf("\n %d\t\t %d\t\t %d\t\t",i,frame[i],base[i]);
} else {
//If the job can not fit in the memory
printf("Job %d Can't fit in the Memory.\n",i+1);
break;
}
}
getch();
}
我只想按照我的要求实现以下程序;
1.首先我根据页码输入物理地址和页面大小就可以进入我的jobs了
2.其次每个作业可以根据作业大小放入页数
3.第三 每次我进入作业时,Memory Block Table (MBT) 应该重新加载并告知可用或占用的内存量
4.最后,如果没有足够的空间来放置较大的作业,则会出现错误
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int ps,np,nf,log;
int alloc[50],base[50],frame[50],page[50];
int i,f,n,pa,fs,pno,add,offset;
int temp;
int f1;
clrscr();
printf("\n\t\t PAGING\n");
printf("\n\t Enter the logical address space:");
scanf("%d",&log);
printf("\n\t Enter the page size:");
scanf("%d",&ps);
printf("\n\t Enter the physical address space:");
scanf("%d",&pa);
fs=ps;
np=log/ps;
nf=pa/fs;
printf("\n\t Number of pages = %d",np);
printf("\n\t Number of frames = %d",nf);
for(i=0;i<nf;i++)
alloc[i]=0;
for(i=0;i<np;i++)
{
temp=rand()%nf;
while(alloc[temp]==1)
temp=rand()%nf;
alloc[temp]=1;
frame[i]=temp;
}
printf("\n Page No \t Frame No \t Base address ");
for(i=0;i<np;i++)
{
base[i]=frame[i]*ps;
page[i]=i;
printf("\n%d\t\t %d\t %d\t\t",i,frame[i],base[i]);
}
getch();
}
【问题讨论】:
标签: c memory-management operating-system paging