文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > 高等教育 > 工学 > 页面调度算法(FIFO,LRU,OPT)
侵权投诉

页面调度算法(FIFO,LRU,OPT)

操作系统实验 页面调度算法(FIFO,LRU,OPT)C语言实现代码

页面调度算法(FIFO,LRU,OPT)2006-11-22 19:29
#include< iostream.h >
#include"stdlib.h"

typedef int QElemType;
#define ok 1
#define overflow 0
#define error 0

typedef struct Qnode {
QElemType data;
struct Qnode *next;
}Qnode,*Queueptr;
typedef struct {
Queueptr front;
Queueptr rear;
}LinkQueue;

InitQueue( LinkQueue &Q ) {
Q.front = Q.rear = ( Queueptr )malloc( sizeof( Qnode ));
if( !Q.front ) exit ( overflow );
Q.front->next =NULL;
return ok;
}

EnQueue( LinkQueue &Q,QElemType e ) {
Queueptr p;
p = ( Queueptr )malloc( sizeof( Qnode ));
if( !p ) exit( overflow );
p->data = e;p->next = NULL;
Q.rear->next = p;
Q.rear = p;
return ok;
}

DeQueue( LinkQueue &Q,QElemType &e ) {
Queueptr p;
if( Q.front == Q.rear ) return error;
p = Q.front->next;
e = p->data;
Q.front->next = p->next;
if( Q.rear == p ) Q.rear = Q.front;
free( p );
return ok;
}

void VisitQueue( LinkQueue Q ) {
Queueptr p;
p = Q.front->next;
while( p ) { cout << p->data << " ";p = p->next; }
}

CompareQueue( LinkQueue Q,int page ) {
Queueptr p;
p = Q.front->next;
while( p ) {
if( p->data == page ) return ok;
p = p->next;
}
return error;
}


void FIFO( int *a,int n,int m ) {
LinkQueue Q;
int page, t = 0,flag = 0,x;

InitQueue( Q );

for( int i = 1;i <= m;i++ )
{
page = a[ i ];
t++;
if( t <= n ) { EnQueue( Q,page );
cout << a[ i ] << " "; }
else {
for( int j = 1;j <= n;j++ )
if( CompareQueue( Q,page ) ) { t--;flag = 1;break; }

if( flag == 0 ) { DeQueue( Q,x );
cout << x << " was taken out "
<< page << " was taken in";
EnQueue( Q,page );
}
cout << endl;
VisitQueue( Q );
cout << ":";
}
flag = 0;
}
cout << "缺页中断数为:" << endl;
cout << "t= " << t << endl;
}

void LRU( int *a,int n,int m ) {
LinkQueue Q;int page, t = 0,flag = 0,x,e;
InitQueue( Q );
for( int i = 1;i <= m;i++ )
{
page = a[ i ];t++;
if( t <= n ) { EnQueue( Q,page );cout << a[ i ] << " "; }
else { for( int j = 1;j <= n;j++ )
if( CompareQueue( Q,page ) ) { t--;DeQueue(Q,e);EnQueue(Q,e);flag = 1;break; }
if( flag == 0 ) { DeQueue( Q,x );
cout << x << " was taken out " << page << " was taken in";
EnQueue( Q,page );
}
cout << endl;
VisitQueue( Q );
cout << ":";
}
flag = 0;
}
cout << "缺页中断数为:" << endl;
cout << "t= " << t << endl;
}


int max( int *t,int n ){
int max =t[ 1 ],s = 1;
for( int i = 1;i <= n;i++ )
if( t[ i ] > max ) {max = t[ i ];s = i;}
return s;
}

void OPT( int a[ 21 ],int n,int m ) {

int w = 0,flag = 0;
int *t =new int[ n + 1 ];

for( int i = 1;i <= m;i++ )
{
w++;
if( w <= n ) cout << a[ i ] << " " ;

else{
for( int q = 1;q <= n;q++ )
if( a[ i ] == a[ q ] ) { w--;fl

第1页

你可能喜欢

热门文档

相关文档

  • 页面置换算法OPT+FIFO+LRU+clock

    页面置换算法OPT+FIFO+LRU+clock_计算机软件及应用_IT/计算机_专业资料。C语言版页面置换算法OPT+FIFO+LRU+clock#include<iostream> #include<fstream> using ...

  • 页式虚拟存储管理FIFO、LRU和OPT页面置换算法

    页式虚拟存储管理FIFO、LRU和OPT页面置换算法_计算机软件及应用_IT/计算机_专业资料。目录 1 需求分析...目录1 需求分析......

  • 页面置换算法模拟——OPT、FIFO和LRU算法

    页面置换算法模拟——OPT、FIFO和LRU算法_计算机软件及应用_IT/计算机_专业资料。操作系统实验报告,含源代码,页面置换算法模拟——OPT、FIFO和LRU算法...

  • fifo_lru_opt

    页面置换算法OPT+FIFO+L... 8页 1下载券 计算机操作系统分页算法... 1页...(visit_pagenumber); } } } LRU 调度算法的实现 //1:访问内存 : //如果...

  • 页式虚拟存储管理FIFO、LRU和OPT页面置换算法

    页式虚拟存储管理FIFO、LRU和OPT页面置换算法_IT/计算机_专业资料。此为课程...、通过完成该课程设计,使我了解了什么是缺页中断,以及处理缺页中断 的调度算法...

  • 页面调度算法的模拟实现

    不常 , 用调度算法( 最佳算法( 用调度算法(LFU)以及最佳算法(OPT) 其中经常被采用、易于实现的是 FIFO 和 LRU )以及最佳算法 ) 其中经常被采用、 ; 算法...

  • 操作系统论文——页面调度算法

    如何选择调度策略即页面置换算法至关重要,置换算法的好坏,直接影响着 系统的性能,因此有必要将常见的 FIFO、LRU、OPT 三种算法进行比较,分析性能。 因此我们需要选择...

  • 操作系统课设 LRU,OPT

    先进先出FIFO页面置换算... 3页 免费 LRU页面置换算法模拟 9页 免费 C++...LRU、 题目: 请求页式管理缺页中断模拟设计-- LRU、OPT 初始条件: 初始条件:...

  • 页面调度实验报告

    设计结构体存放页面调度顺序串及内存块 2、分别模拟 FIFO 置换调度算法、LRU 置换调度算法以及 OPT 置换调度算法进行页面调度 3、分别打印输出 3 种置换算法调度后...

  • OPT与LRU

    LFU实现比较困难,目前多用LRU进行页面替换 2)RAND、FIFO、LRU及OPT算法 ·RAND算法:用软硬件的随面数产生主存中要被替换页的页号。 ·FIFO算法:选择最早装入...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email