Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Middle Test

Student’s name: Bùi Văn Nhật


ID:

Q1 (2.0 points):
In the console or terminal window, type the following LINUX commands on the command
line.
Note and write down the results
$ ls
$ pwd
$ps
$ cd ..
$ pwd
$ cd /usr/local
$ ls

Q2 (2.0 points):
- Create a file named user.txt. Then, you add n usernames (each in one line, n>=5). (cat
>)
cat > user.txt
- Display the content of file user.txt (cat )
Cat user.txt
- Display list of n sorted usernames in your file and store that sorted list into a new file
named suser.txt (sort)
cat user.txt| sort> suser.txt
- Count the number of users in your file and display it.
cat -n user.txt
Q3 (2.0 points): For each of the following decimal virtual addresses, compute the virtual
page number and offset for a 4-KB page and for an 8 KB page: 20000, 32768, 60000.

2.1 Page size = 4KB

Virtual address Page number Offset

20000 4 1824

32768 8 0

60000 14 2392

2.2 Page size = 8KB

Virtual address Page number Offset

20000 2 3616

32768 4 0

60000 7 2360

Q4 (2.0 ponts): A memory free in 3 frames. How many page fault occur after running
as the following page 7, 0 , 1, 2 , 0, 3, 0 , 4, 2 , 3 , 0 , 3 , 2 , 1, 2, 0, 1, 0 , 7 using
FIFO

7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 0 7

F1 7 7 1 2 2 3 3 3 3 3 3 3 3 1 1 1 1 1 1

F2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7

F3 7 7 7 7 7 4 4 4 4 4 4 4 4 4 4 4 4

PF x x x x x - - - - - x - - - - x

Q5 (2.0 ponts): A computer has four page frames. The time of loading, time of last
access, and the R and M bits for each page are as shown below
(the times are in clock ticks):

Page Loaded Last Ref. R M


0 230 285 1 0
1 120 265 0 0
2 140 270 0 1
3 110 280 1 1
(a) Which page will NRU replace? (1)

The Not Recently Used (NRU) page replacement algorithm replaces the page with
the lowest combination of R and M bits set to 0. In this case, pages 1 and 2 have R and
M bits set to 0, but page 1 has a lower load time than page 2, so page 1 will be replaced.

(b) Which page will FIFO replace? (3)

The First-In-First-Out (FIFO) page replacement algorithm replaces the page that has
been in memory the longest. According to the table, page 0 was loaded at 230 and is the
oldest page, so it will be replaced.

(c) Which page will LRU replace? (1)

The Least Recently Used (LRU) page replacement algorithm replaces the page that has
not been accessed for the longest time. According to the table, page 1 was last
referenced at 265, which is the oldest last reference time, so it will be replaced.

(d) Which page will second chance replace? (1)

The Second Chance page replacement algorithm is a modification of the FIFO algorithm
that gives a second chance to pages that have been accessed since their last
consideration for replacement. It scans the pages in a circular order and gives a second
chance to the first page with the R bit set to 1. If all the R bits are 0, the page will be
replaced as in FIFO. In this case, the circular order is 0-1-2-3-0-1-2-3-..., and the first
page encountered with R bit set to 1 is page 3, so it will be given a second chance. The
next time the circular order comes to page 3, its R bit will be cleared, but it will not be
replaced. The next page in the circular order is page 0, which is the oldest page, so it
will be replaced. Therefore, page 1 will be replaced, and page 3 will get a second chance.

You might also like