社区
C语言
帖子详情
急!!!!求操作系统 最近未使用(NRU)页面置换算法!!!!!!
jl_7777
2006-12-09 08:15:34
求操作系统最近未使用(NRU)页面置换算法的C++/C语言实现,除用于学习外还关系到本人的处境问题,具体情况就不好意思说了……………………
先谢谢各位了!!!
...全文
833
6
打赏
收藏
急!!!!求操作系统 最近未使用(NRU)页面置换算法!!!!!!
求操作系统最近未使用(NRU)页面置换算法的C++/C语言实现,除用于学习外还关系到本人的处境问题,具体情况就不好意思说了…………………… 先谢谢各位了!!!
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
「已注销」
2006-12-10
打赏
举报
回复
唉,
这么好的一个学习机会,
楼主就这么浪费了么?
WaterWalker
2006-12-10
打赏
举报
回复
---------
唉,
这么好的一个学习机会,
楼主就这么浪费了么?
-----
laiwusheng
2006-12-10
打赏
举报
回复
#include <stdio.h>
#include <stdlib.h>
#define MAX 50
#define n 10
#define m 10
#define blocklength 100
typedef struct
{
int flag;
int page[n][2];
int length;
int stack[n];
int slength;
int rear;
}pbc;
pbc a[MAX];
int pbcnum=MAX;
int MEM[m][m];
int memnum;
int I,J;
main()
{
void init();
void create();
void lookp(int num);
void lookm();
void help();
void fifo_lru(char type);
void end();
void search();
char ch;
init();
do
{
printf("\nWhat do you want to do?");
help();
printf("\nSELECT: ");
ch=bioskey(0);printf("%c",ch);
switch(ch)
{
case'c':
case'C':
create();
break;
case'r':
case'R':
printf("\nFIFO or LRU.(f or l)\nAnswer: ");
ch=bioskey(0);printf("%c",ch);
fifo_lru(ch);
break;
case'e':
case'E':
end();
break;
case'l':
case'L':
lookm();
break;
case'#':
printf("\nThe END.");
sleep(1);
return;
}
}while(ch!='#');
}
void end()
{
int i,t,num,lt,pt,pn;
char ch;
do
{
printf("\nInput the pbc number: ");
scanf("%d",&num);getchar();
if (a[num].flag==0)
{
printf("\nThe pbc hasn't create.");
sleep(1);
return;
}
for (i=0;i<n;i++)
{
if (a[num].page[i][0]!=0)
{
if (a[num].page[i][0]%m==0)
MEM[(a[num].page[i][0]/m)-1][m-1]=0;
else
MEM[a[num].page[i][0]/m][(a[num].page[i][0]%m)-1]=0;
a[num].page[i][0]=0;
a[num].page[i][1]=0;
}
a[num].stack[i]=0;
}
a[num].length=0;
a[num].slength=0;
a[num].rear=-1;
a[num].flag=0;
printf("\nDo you want end another PBC?\nAnswer: ");
ch=bioskey(0);printf("%c",ch);
}while(ch!='n' && ch!='N');
}
void fifo_lru(type)
char type;
{
int i,t,num,lt,pt,pn;
char ch;
printf("\nInput the pbc number: ");
scanf("%d",&num);getchar();
if (a[num].flag==0)
{
printf("\nThe pbc hasn't create.");
sleep(1);
return;
}
do
{
printf("\nInput the Logical address.\nLogical address: ");
scanf("%d",<); getchar();
pn=lt/blocklength;
if ( pn < a[num].length )
{
if (a[num].page[pn][1]==1)
{
printf("\nThe Physical address: %d",(a[num].page[pn][0])*blocklength+lt%blocklength);
if (type=='l' || type=='L')
{
i=0;
while(a[num].stack[i]!=pn)
i++;
for (;i<a[num].rear;i++)
a[num].stack[i]=a[num].stack[i+1];
a[num].stack[a[num].rear]=pn;
}
}
else
{
printf("\nDiaoDu:");
if (a[num].slength>a[num].rear+1)
{
search();
a[num].page[pn][0]=I*m+J+1;
a[num].page[pn][1]=1;
a[num].stack[++a[num].rear]=pn;
printf("\nThe Physical address: %d",(a[num].page[pn][0])*blocklength+lt%blocklength);
}
else
{
a[num].page[a[num].stack[0]][1]=0;
a[num].page[pn][0]=a[num].page[a[num].stack[0]][0];
for (i=0;i<a[num].rear;i++)
a[num].stack[i]=a[num].stack[i+1];
a[num].page[pn][1]=1;
a[num].stack[a[num].rear]=pn;
printf("\nThe Physical address: %d",(a[num].page[pn][0])*blocklength+lt%blocklength);
}
}
}
else
printf("\Out of side.");
lookp(num);
printf("\nDo you want input another Logical?\nAnswer: ");
ch=bioskey(0);printf("%c",ch);
}while(ch!='n' && ch!='N');
printf("\n\nPress any key back to the MENU.");
bioskey(0);
}
void search()
{
if (memnum!=0)
{
for (I=0;I<m;I++)
for (J=0;J<m;J++)
if (MEM[I][J]==0)
{
MEM[I][J]=1;
return;
}
}
else
printf("\nThere is no mem left.");
}
void lookm()
{
int i,j;
clrscr();
for (i=0;i<m;i++)
{
printf("\n");
for (j=0;j<m;j++)
printf("%-2d",MEM[i][j]);
}
printf("\n\nPress any key back to the MENU.");
bioskey(0);
}
void create()
{
int i;
if (pbcnum==0)
{
printf("\ncann't create any more.");
sleep(1);
return;
}
else
{
pbcnum--;
i=0;
while(a[i].flag!=0)
i++;
a[i].flag=1;
printf("\nThe < %d > pbc is built.",i);
printf("\nInput the page's length: ");
scanf("%d",&a[i].length);
printf("Input the stact's length: ");
scanf("%d",&a[i].slength);
}
printf("\nPress any key back to the MENU.");
bioskey(0);
}
void lookp(num)
int num;
{
int i;
if (a[num].flag!=0)
{
printf("\nThe page: ");
for (i=0;i<a[num].length;i++)
if (a[num].page[i][1]!=0)
printf("\npage < %d > is in the mem %d.",i,a[num].page[i][0]);
printf("\nThe stack: ");
for (i=0;i<=a[num].rear;i++)
printf("%d ",a[num].stack[i]);
}
else
{
printf("\nThis produce hasn't create.");
sleep(1);
}
}
void help()
{
clrscr();
printf("\nC Create a produce.");
printf("\nR RUN (FIFO or LRU).");
printf("\nE End one PBC.");
printf("\nL Look MEM.");
printf("\n# End one demostration.");
}
void init()
{
int i,j;
for (i=0;i<MAX;i++)
{
a[i].flag=0;
for (j=0;j<n;j++)
{
a[i].page[j][0]=0;
a[i].page[j][1]=0;
a[i].stack[j]=0;
}
a[i].length=0;
a[i].slength=0;
a[i].rear=-1;
}
for (i=0;i<m;i++)
for (j=0;j<m;j++)
MEM[i][j]=0;
memnum=(m*m);
}
jixingzhong
2006-12-10
打赏
举报
回复
唉,
这么好的一个学习机会,
楼主就这么浪费了么?
fosjos
2006-12-10
打赏
举报
回复
http://deepdeep53.bokee.com/
NRU写成NUR了,搜索一下NRU和nurorder就可以了
jl_7777
2006-12-10
打赏
举报
回复
二楼的同志可能没看清楚吧,我找的是NRU算法,你给的这个LRU算法我也有了,不过还是多谢了!
多谢各位的提醒,主要是最近时间太紧了,来不及慢慢研究啊
页面置换算法
FIFO,LRU,
NRU
,OPT
封装了大部分的
页面置换算法
FIFO,LRU,
NRU
,OPT 属于
操作系统
课程设计的一部分
操作系统
课程设计
页面置换算法
FIFO和 LRU
这是一个自己完成软件工程的
操作系统
课程课程设计题目:此程序用于模拟虚拟磁盘
页面置换算法
,实现了FIFO
页面置换算法
和LRU
页面置换算法
,获得课程设计优秀的好成绩
操作系统
课设 常用
页面置换算法
模拟实验
操作系统
课程设计小题--常用
页面置换算法
模拟实验
操作系统
最近
最久
未
使用
页面置换算法
操作系统
课程设计
最近
最久
未
使用
页面置换算法
操作系统
页面置换算法
包括了
操作系统
页面置换算法
,其中有OPT,FIFO,LRU,CLOCK,改进型的CLOCK算法
C语言
70,037
社区成员
243,243
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章