|
-
September 17th, 2002, 01:27 AM
#1
Scheduling Algorithm - Who Can Give Sample Program???
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
-
September 17th, 2002, 02:48 AM
#2
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.
Succinct is verbose for terse
-
September 17th, 2002, 03:21 AM
#3
You mean something like this, or did I understand your question totally wrong?
Code:
#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;
}
-
September 17th, 2002, 04:05 AM
#4
thanks to both of you!
bright minds, bright ideas!
-
November 3rd, 2007, 10:54 PM
#5
Re: Scheduling Algorithm - Who Can Give Sample Program???
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.
-
November 5th, 2007, 05:47 PM
#6
Re: Scheduling Algorithm - Who Can Give Sample Program???
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
Code:
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
Succinct is verbose for terse
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|