Click to See Complete Forum and Search --> : Scheduling Algorithm - Who Can Give Sample Program???
jonelo
September 17th, 2002, 01:27 AM
DO YOU REMEMBER PAGE REPLACEMENT AGORITHMS???
FIRST-IN-FIRST-OUT
LEAST FREQUENTLY USED
MOST FREQUENTLY USED
CAN ANYONE PROVIDE ME SAMPLE PROGRAM WIH SOURCE CODE IN C OR IN C++ FOR THESE ALGORITHM?
PLEASE IF YOU HAVE KINDLY EXTEND THEM TO ME...
THANK YOU VERY MUCH
cup
September 17th, 2002, 02:48 AM
Most Frequently Used is a new one - never heard of that before. You've missed out Least Recently Used. The algorithms are quite easy to implement anyway
FIFO - just implement a queue
LFU - increment page counter whenever a page is accessed. Take out the one with the smallest counter
MFU - increment page counter whenever a page is accessed. Take out the one with the biggest counter
LRU - increment a global counter whenever a page is accessed and set the page counter to that value. Take out the one with the lowest counter.
This of course assumes that you won't page so much that it wraps past the maximum integer. It is OK for experimental purposes.
Gabriel Fleseriu
September 17th, 2002, 03:21 AM
You mean something like this, or did I understand your question totally wrong?
#include <list>
#include <iostream>
class basic_task
{
public:
virtual void operator()() = 0;
virtual ~basic_task(){};
};
class task_1:public basic_task
{
public:
virtual void operator()(){std::cout<<"task_1"<<std::endl;}
virtual ~task_1(){}
};
class task_2:public basic_task
{
public:
virtual void operator()(){std::cout<<"task_2"<<std::endl;}
virtual ~task_2(){}
};
class scheduler
{
std::list<basic_task *> task_list;
public:
void push(basic_task *t){task_list.push_back(t);}
void run(){
std::list<basic_task *>::iterator it;
for(it=task_list.begin(); it!=task_list.end(); ++it){
(**it)();
delete (*it);
}
task_list.clear();
}
};
int main()
{
scheduler s;
s.push(new task_1());
s.push(new task_2());
s.push(new task_1());
s.push(new task_2());
s.run();
return 0;
}
jonelo
September 17th, 2002, 04:05 AM
thanks to both of you!
bright minds, bright ideas!
:)
Zenlakin
November 3rd, 2007, 10:54 PM
How would I implement something like that in both a FIFO and LRU scenario while passing a string of predefined numbers and a set page file size. Like FIFO with string 1,2,3,4,5 and page file of say 3? And the same for LRU. I am not a programmer but would like to see how this works in a running simulation to help me better understand how it really works in an operating system. Thanks.
cup
November 5th, 2007, 04:47 PM
You should really make up your own thread referencing this one. While you're on this topic, you might like to look up Belady's anomaly.
Can't give you a program but can make up a short example
Page
1 LRU 1 FIFO 1
2 LRU 2 1 FIFO 2 1
1 LRU 1 2 FIFO 2 1
3 LRU 3 1 2 FIFO 3 2 1
1 LRU 1 3 2 FIFO 3 2 1
4 LRU 4 1 3 FIFO 4 3 2
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.