You are on page 1of 5

Serial No:

CS205 Operating Systems Final Term Exam


Monday, July 06, 2020 Spring Semester 2020
Course Instructor Max Time:3 Hour
Mr. Muhammad Usman Joyia Max Marks: 100
Exam Weight (40 Out of 100).

_____________________ . .
Roll No Section

Guidelines for Submission:

1. You should submit only one PDF document and all text should be typed. Equations, f
igures can be taken as pictures (all figures/equations can be pasted as images inside th
at document).
2. You must submit your solution before due time via Slate/Google Classroom. Submis
sions submitted after the due time shall not be considered.
3. If you don’t finish every part of a question, don’t worry! You can still submit what
you’ve done to get marks based on your efforts.
4. In case of copied or plagiarized solutions in exam Or If a student provided help to ano
ther student during exam both will be awarded "F" grade and it will affect the student
CGPA.
5. Viva of any student can be conducted by the instructor after conducting an online exa
m in case of any doubt.
6. This document should be submitted through LMS (Slate/Google Classroom). But in
worst case, you can email it within the deadline.

CLO NO. 03-06 04 05 06 06


Q1 Q2 Q3 Q4 Q5 Total
Total Marks 40 15 20 15 10 100
Obtained Marks
National University of Computer and Emerging Sciences
Department of Computer Science Chiniot-Faisalabad Campus

Question No. 2: [5+5+5Marks] [CLO4]

A. There is direct relation of mutual exclusion with the execution of wait and signal operations.
If wait and signal operations are restricted to execute atomically mutual exclusion between the
processes cannot be violated and vice versa. Is it this statement true? Explain.

A wait operation atomically decrements the value associated with a semaphore. If two wait
operations are executed on a semaphore when its value is 1, if the two operations are not
performed atomically, then it is possible that both operations might proceed to decrement
the semaphore value, thereby violating mutual exclusion. But if these operations are
executed atomically, this will make sure mutual exclusion holds by restricting other
processes to enter into the critical section if there’s already a process in it.

B. We have observed that spinlocks are more preferred to use in multiprocessor environment.
Discuss the reasons thoroughly why it is avoided to be used in single process environment.

Spinlocks are not appropriate for single-processor systems because the condition that would
break a process out of the spinlock can be obtained only by executing a different process. If
the process is not relinquishing the processor, other processes do not get the opportunity to
set the program condition required for the first process to make progress. In a multiprocessor
system, other processes execute on other processors and thereby modify the program state
in order to release the first process from the spinlock.

C. As we know the Critical section is used to guard the shared variables. Likewise, considering
a Multi-thread programs that use no shared variables is always deadlock free? Discuss it.
Yes, as no shared variable will leads towards no critical section problem.

Question No. 3. [12+8 Marks] [CLO5]


A. Consider a street consisting four different sections in a colony. There’s only one vehicle in
the first section of street. In the second section, three vehicles are occupying the space and
waiting to move to other section. In third section, two vehicles are waiting for the next vehicle
in front of them to move. There are five vehicles in section four stuck in way that section space
cannot be taken away from them until they moves into next section. Considering the situation
of all mentioned four sections, differentiate between following terms by analyzing which
section exist into which term:
i) Hold and Wait ii) Mutual Exclusion iii) No Preemption iv) Circular Wait

Also discuss what rule should be devised for vehicles to cross the street (intersected by four
sections) in a way that there’s no deadlock?

Mutual exclusion: only one vehicle on a section of the street


Hold and wait: each vehicle is occupying a section of the street and is waiting to move to the
next section
No preemption: a section of a street that is occupied by a vehicle cannot be taken away from
the vehicle unless the car moves into the next section
Circular wait: each vehicle is waiting for the next vehicle in front of it to move

Deadlock free rule: allow a vehicle to cross the intersection only if it make sure it doesn’t
stop at it.
Final Exam Spring-2020 Page 2 of 5
National University of Computer and Emerging Sciences
Department of Computer Science Chiniot-Faisalabad Campus

B. Is it possible for the two threads to deadlock by concurrent calls to the functions A and B below? If
so, give an example of an execution trace that leads up to deadlock. If not, explain why deadlock is
impossible, appealing to the four necessary conditions for deadlock.
void A (){ void B (){
... ...
pthread_mutex_lock (&M2); pthread_mutex_lock (&M1);
pthread_mutex_lock (&M1); pthread_mutex_lock (&M2);
... critical section ... ... critical section ...
pthread_mutex_unlock (&M1); pthread_mutex_unlock (&M2);
pthread_mutex_unlock (&M2); pthread_mutex_unlock (&M1);
} }

There is a deadlock if the two processes execute in the following interleaved order:
Func instruction status
A pthread_mutex_lock (&M2); succeeds
B pthread_mutex_lock (&M1); succeeds
A pthread_mutex_lock (&M1); blocks
B pthread_mutex_lock (&M2); blocks

Question No. 4 [10+5 Marks] [CLO6]

A. If a process of size 60,588 bytes is required to be loaded into memory and pages size is kept
at 2048 bytes for computer A and 1024 for Computer B. How many pages will be required to
store the process into the memory for both Computers? Is there any internal fragmentation? If
yes, calculate the internal fragmentation. Also discuss which of the page size is more
appropriate w.r.t page table.

Computer A Computer B

Total process size = 60,588 Total process size = 60,588


Page size = 2048 Page size = 1024
Number of full loaded frames required = Number of full loaded frames required =
60588 / 2048 = 29 pages 60588 / 1024 = 59 pages

Total bytes left unloaded = 1196 Total bytes left unloaded = 172

If we load it in new frame, then internal If we load it in new frame, then internal
fragmentation will occur. fragmentation will occur.

Internal fragmentation = 2048 – 1196 = 852 Internal fragmentation = 1024 – 172 = 852
bytes bytes

Final Exam Spring-2020 Page 3 of 5


National University of Computer and Emerging Sciences
Department of Computer Science Chiniot-Faisalabad Campus

We have observed from the above mentioned solution that the internal fragmentation is same
for both cases but more number of pages is required. This will lead towards the large page
table as well that also need to be store on the memory. So from this perspective, computer A
is have more appropriate page size

B. Calculate the effective access time if hit ratio is 70%, memory access time is 120ns and
TLB search time is 30ns.

Hit ratio = 70%


Miss ratio = 100 – hit ratio = 30%
Memory access time = 120ns
TLB search time = 30ns

Effective memory access time = hit ratio (TLB Time + Access Time) + Miss Ratio(TLB Time +
2*Access Time)

Effective memory access time = 0.7 ( 30 + 120 ) + 0.3(30 + 2(120))


= 0.7(150) + 0.3(270) = 105+81 = 186 ns

Question No 5: [6+4 Marks]

Consider the following information

AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH

Whereas logical address space is 32bytes, page size is 4bytes and physical memory space is
64bytes.
I. Calculate the number of bits in the logical address and physical address?

Logical address space size = 25


Physical address space size = 26
Page size = 22

Logical address = 2 + 5 = 7 bits


Phy address = 2 + 6 = 8 bits

II. Draw a mapping of logical address space to physical address space (pages to frames
with page table) (Only use Table Drawing Tool of MS Word)

Note: Specifically mention the bits for each page, page table entries and frames
and carefully assign the data to each page. You can randomly assign the
addressing schemes for page table but that should be in range.

Final Exam Spring-2020 Page 4 of 5


National University of Computer and Emerging Sciences
Department of Computer Science Chiniot-Faisalabad Campus

0 A 0
1 A 1
2 A 2
3 A 3
4 B 4 A
5 B A
6 B A
7 B 0 1 A
8 C 8 F
9 C 1 3 F
10 C F
11 C 2 5 F
12 D 12 B
13 D 3 4 B
14 D 4 7 B
15 D B
16 E 5 2 16 D
Page Table
17 E D
18 E 6 8 D
19 E D
7 10
20 F 20 C
21 F C
22 F C
23 F C
24 G 24
25 G 28 E
26 G E
27 G E
28 H E
29 H
32 G
30 H
G
31 H
G
Logical Address Space G

36
40 H
H
H
H
44
.
.
.
60
61
62
63

Physical Address Space

Final Exam Spring-2020 Page 5 of 5

You might also like