0% found this document useful (0 votes)
16 views3 pages

2017 - Midterm 2 - Fall - OS

This document is an exam paper for the Operating System course (CS-205) at the National University of Computer and Emerging Sciences, Lahore Campus, for the Fall 2017 semester. It includes instructions for answering questions, a series of questions related to memory allocation algorithms, logical address translation, page fault handling, and a proposed solution for the readers-writers problem. The exam is designed to assess students' understanding of key concepts in operating systems, with a total of 50 marks available.

Uploaded by

Shazil Hamzah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

2017 - Midterm 2 - Fall - OS

This document is an exam paper for the Operating System course (CS-205) at the National University of Computer and Emerging Sciences, Lahore Campus, for the Fall 2017 semester. It includes instructions for answering questions, a series of questions related to memory allocation algorithms, logical address translation, page fault handling, and a proposed solution for the readers-writers problem. The exam is designed to assess students' understanding of key concepts in operating systems, with a total of 50 marks available.

Uploaded by

Shazil Hamzah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

National University of Computer and Emerging Sciences, Lahore Campus

Course: Operating System Course Code: CS-205


Program: BS(Computer Science) Semester: Fall 2017
Duration: 1 hour Total Marks: 50
Paper Date: 2nd November, 2017 Weight: 15%
Section: All Page(s): 3
Exam: Mid-2 Roll No.
Instructions/Notes: Answer questions on the question paper. Write answers clearly and precisely, if the answers are not
easily readable then it will result in deduction of marks. Use extra sheet for rough work, cutting and blotting on this sheet
will result in deduction of marks.

Question 1 (10 points): Given below are two tables. The first table shows the processes coming in order (a process with
lower number comes earlier than the one with greater number). Using best fit algorithm assign each process some hole
given in the following table. Also calculate the remaining space.

Required Memory
Process#
(MBs)
1 20
2 43
3 21
4 77
5 6
6 11
7 15
8 105
9 62
10 90

Hole# Hole Size (MBs) Allotted Process# Remaining space


1 83
2 50
3 100
4 25
5 30
6 10
7 70
8 15
9 17
10 110

Question 2 (4 points): If you use worst fit algorithm instead, then which hole will be assigned to first two processes

• Process 1 → Hole#= • Process 2 → Hole#=

Question 3 (6 points): Extract page numbers and offsets from the following logical addresses. The page size is 1000
bytes.

• 2101 → Page#= Offset= • 5215 → Page#= Offset=


• 102 → Page#= Offset=

School of Computer Science Page 1 of 3


Question 4 (15 points): Using the below given functions you have to implement a function handlePageFault. It is
called when a page fault occurs. Meaning, when a page is not found loaded into the memory, it load it and fixes the page
table. Use following functions without the knowledge of their definition. Comments describe their functionality. The
page table is a two level page table stored without caching. Hint: read the declarations carefully!

int g e t F i r s t L e v e l P a g e N u m b e r ( int logicalAddress ) ; // takes the faulty logical address as input


and returns the a s s o c i a t e d first level page number .

int g e t S e c o n d L e v e l P a g e N u m b e r ( int logicalAddress ) ; // takes the faulty logical address as input


and returns the a s s o c i a t e d second level page number .

int g e t C o m b i n e d P a g e N u m b e r ( int logicalAddress ) ; // takes the faulty logical address as input


and returns the value of bits a s s o c i a t e d to the page number ( first and second level ) .

int * g e t F i r s t L e v e l P a g e T a b l e ( int PID ) ; // takes the process ID as input and returns the pointer
to its first level page table .

int l o a d P a g e F r o m B a c k i n g S t o r e ( int combinedPageNumber , int PID ) ; // takes the page number and
process ID as inputs and returns the frame number on which it loaded the page .

void handlePag eFault ( int logicalAddress , int PID ) // the faulty address and the process ID are
the p a r a m e t e r s to the function .
{

School of Computer Science Page 2 of 3


Question 5 (15 points): Following is a proposed solution for readers writers problem. Although the solution fulfills
some requirements, but it does violate “The Bounded Wait” property. Which means that in this case the writer may have
to wait indefinitely. Remove that problem by inserting new semaphore(s). For 100% marks propose a solution which
gives a better chance to writers to enter into the critical section.

Code for Writers Code for Readers


roomEmpty=0,mutex=0, readers=0 // all variables are shared

1: [Link]()
2: readers + +
3: if readers == 1 :
4: [Link]()
1: [Link]() 5: [Link]()
2: Write(Rsc) 6: Read(Rsc)
3: [Link]() 7: [Link]()
8: readers − −
9: if readers == 0 :
10: [Link]()
11: [Link]()

School of Computer Science Page 3 of 3

You might also like