Вы находитесь на странице: 1из 4

CSE 313 Assignment

Total Mark : ​15

Problem 1: 8

Implement ​NFU Page replacement algorithm with Aging for a system with 4 physical
page frames. For simplicity, consider that a clock interrupt occurs after every 3 page
references.

Input:

Input will be taken from a file named ​in1.txt​. The first line will contain an integer ​n​.
The second line will contain ​n integers separated by a space. These integers denote the
virtual page numbers those are referenced in the same order. An example is as
followed:

12
2 1 4 4 4 2 3 4 2 6 7 7

Output:

The output should be redirected to a file named out1.txt. For every page referenced,
print the page number followed by the entire page table after this page is accessed. The
page table must contain (but not limited to) the following attributes:

● Virtual Page Number


● Physical Page Number
● Reference bit
● Counter (8 bit)
The output for the sample input will look like following:

2
VPN PPN R bit Counter

## ## ## ##

## ## ## ##

## ## ## ##

## ## ## ##

1
VPN PPN R bit Counter

## ## ## ##

## ## ## ##

## ## ## ##

## ## ## ##

4
VPN PPN R bit Counter

## ## ## ##

## ## ## ##

## ## ## ##

## ## ## ##

………… and so on.


Problem 2: 7

Implement Banker’s Algorithm for deadlock prevention for a system with ​p ​processes
and ​r​ different types of resources.

Input:

Input will be taken from a file named ​in2.txt​. Format of input file will be as followed:
● Line 1 will contain two integers​ p​ and ​r
● Line 2 will contain ​r integers separated by space. This is the vector for existing
resources.
● Then there will be ​p lines each containing ​r integers separated by space. This
pxr​ matrix denote the resources assigned to each process currently.
● There will be again ​p lines containing ​r integers each. This denote the matrix for
resources still needed by the processes.
A sample input file may look like following: (Same example as shown in your book)

5 4
6 3 4 2
3 0 1 1
0 1 0 0
1 1 1 0
1 1 0 1
0 0 0 0
1 1 0 0
0 1 1 2
3 1 0 0
0 0 1 0
2 1 1 0

Output:

Output one line containing any of the words “​safe​” or “​unsafe​” depending on whether
the current state is safe or unsafe respectively. Output may be given to standard output.
Special Notes:
1. You have to submit the problem solutions in moodle by January 25, 2018, 11:55
pm. The submission rules will be available in details in moodle.
2. Solutions must be written in C/C++ (Compilable with gcc/g++).
3. Plagiarism will be penalized with 100% of assignment marks.

Вам также может понравиться