1. (a) What is trashing and list possible causes of thrashing.

(b) How does the operating system detect thrashing and what can it do to eliminate thrashing?

[15 marks]

2. The given program simulates the effect of changing page sizes in a demand paging system. The following sequence of request is taken from 460-word program: 10, 11, 104, 170, 73, 309, 185, 245, 246, 434, 458, 364.

Main memory can hold total of 200 words for this program and the page frame size will match the size of pages into which the program has been divided. The page numbers are calculated according to the page size; divide by the page size, and the quotient gives the page number. The number of page frames in memory is the total number, 200, divided by page size.

(a)
(i) What does function int find_page_in_memory(int page, Memory * memory) do?

(ii) Which memory allocation scheme is used in the program? Explain how it is implemented.

(iii) What is the use of struct in the program?

(b)
(i) Add some code in the program to find the success frequency or the percentage of successful request hit?

(ii) Find the success frequency for 100-words, 50-words, and 200-words. What conclusion can you make?

(iii) What do you think will happen if more memory were given to the program?

[45 marks]


3.
(a) Modify the program so that it uses the Least Recently Used page replacement algorithm.

(b) Find the success frequency of the new algorithm by repeating question 2 (b) (ii).

(c) Compare the results of the two algorithms.

(d) Assuming that you are developing a new operating system (for the present days applications), what type of memory allocation scheme you would use and why? Note: Marks will be awarded based on your creativity and suggestions (which should be beyond your text books).

[40 marks]

Attachments
#include<queue>
#include<iostream>
#include<string>
#include<list>
#include<fstream>

using namespace std;

struct info{
    int page_frame;
    int page_num;    
};

int PROGRAM = 460;
int MEMORY = 200;

int pageSize()
{
	char doYou = 'y';
	int page_Size;

	cout<<"\nMain Memory Size is :"<<MEMORY;
	cout<<"\nDefault page size 100";
	cout<<"\nDo you want to change the page size ?(y-YES,n-NO):";
	cin >> doYou;
	if(doYou == 'y'){
		cout<<"Enter the Page Size (only even number):";
		cin >>page_Size;
	}
	else{
		cout<<"\nPage Size 100 is selected";
		page_Size = 100;
	}
	return page_Size;
}

int find_page_in_memory(int req_word,int page_Size,int memory,queue<info> memori)
{
	int quotient;
	int pageframe;
	int find;
	int i=0;
	int pno;
	int hits=0;

	pageframe = memory/page_Size;
	quotient = req_word/page_Size;
	
	//info dataType5=memory.front();
	info dataType6;
	pno= req_word/page_Size;

	while(i<pageframe){
				
		dataType6=memori.front();
		
		if((pno==dataType6.page_num)&&(hits==0)){
			return find =1;
		}
		memori.pop();
		memori.push(dataType6);
		i++;
	}
	return find =0;
}

void main()
{
    int a=0;
	int b=0;
    int page_Size;
	
	page_Size = pageSize();

	int pf=0;
    pf=MEMORY/page_Size;
	
	// define the queue using STL
	queue<info> memory;
	
	for(int x=0;x<pf;x++)
	{ 
		info dataType2;
		dataType2.page_frame=x;
		dataType2.page_num=x;
		memory.push(dataType2);  
	}    

	int counter=-1,miss=0,hit=0;
	char namafail[10];
	int request_word;
	ifstream request;

	cout<<"\nPlease enter the request file name :";
	cin >> namafail;
	cout<<endl;
	cout<<"Request"<<"   Page Num"<<"\tPage Frame"<<" "<<"    Hit/Miss"<<endl<<endl;
	request.open(namafail);
	while(!request.eof()){
		
		request>>request_word;

		if(!(find_page_in_memory(request_word,page_Size,MEMORY,memory))){
		
			miss++;
			counter=0;
			info dataType3;
			info dataType4;

			dataType3=memory.front();
			dataType4.page_frame=dataType3.page_frame;
			dataType4.page_num=request_word/page_Size;
			
			cout<<"  "<<request_word<<"\t     "<<dataType4.page_num<<"\t\t    "<<dataType4.page_frame<<"\t\t MISS"<<endl;
			
			memory.pop();
			memory.push(dataType4);

		}
		else{
			
			int i =0;
			int pno =0;
			int hits=0;

			hit++;
			
			info dataType5=memory.front();
			info dataType6;

			pno= request_word/page_Size;

			while(i<pf){
				
				dataType6=memory.front();
				
				if((pno==dataType6.page_num)&&(hits==0)){

					cout<<"  "<<request_word<<"\t     "<<dataType6.page_num<<"\t\t    "<<dataType6.page_frame<<"\t\t HIT"<<endl;
					hits++;
				
				}
				
				
				memory.pop();
				
				memory.push(dataType6);
				

				i++;
			}
		}		
		
		request_word=0;				
	}
	cout<<endl;
}

Hello,

We can't!

The idea of a community such as DaniWeb is for a group participation and learning by solving the problem. It is also unethical for A) us to do your homework, and B) for you to accept our work as your homwork. No! Your post also looks like a take-home exam. It is fortunate that your teacher/professor didn't put in contact information on the attachment, or someone who was really ethically motivated could have contacted him and caused you a lot of trouble.

What can we do?

You are the student. We can make suggestions to your code, and help correct it, but the guts of the code have to be yours. Spend an hour, and start with either a basic flow chart, or write down some psudeo-code (code that is not correct, but gets the idea) and we will build from there.

Anyone who just emails you the answer is not working with the spirit of learning, regardless of any impending deadlines.

We await your code submission...

Christian

Yea,we aint answering machines nor auto homework doers.We help out solving difficulties.

:),Have fun(Btw by welcome)

thnks jenny for your questions, and for those who posted the solution, thank you very much, u help me a lot :))

thnks jenny for your questions, and for those who posted the solution, thank you very much, u help me a lot :))

you forgot to use the [sarcastic] and [/sarcastic] tags :cheesy:

thnks jenny for your questions, and for those who posted the solution, thank you very much, u help me a lot :))

Please don't resurrect dead threads.

This article has been dead for over six months. Start a new discussion instead.