0% found this document useful (0 votes)
123 views10 pages

OS Paper

paper

Uploaded by

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

OS Paper

paper

Uploaded by

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

FAZAIA BILQUIS COLLEGE OF EDUCTION FOR WOMEN

PAF Nur Khan, Rawalpindi


FINAL TERM EXAMS, FALL, 2021

Subject: Operating Systems Class: BS (CS)


Subject Code: Time: 20 mins Max. Marks: 20
Semester: 5th (A & B)
Name: ___________________________ Roll No. _________________ Section: ______________

PART – I (OBJECTIVE)
Q1. Q#1.Select the correct option.
1. A thread shares its resources (like data section, code section, open files, signals) with
a.other process similar to the one that the thread belongs to b.other threads that belong to similar
processes
c.other threads that belong to the same process d. All of these
2. In operatong systems,each process has its own
a.Address space and global variables b.open files
c.Pending alarms and signals d.all of the mentioned
3. A system has 3 processes sharing 4 resources. If each process needs a maximum of 2 units then, deadlock
a. can never occur b. may occur
c. has to occur d. none of the mentioned
4. What do you mean by memory compaction?
a.Combine multiple equal memory holes into one big hole b.Combine multiple small memory holes
into one big hole c.Divide big memory hole into small hole
d.Both A & B
5.__________ is generally faster than _________ and _________.
a. first fit, best fit, worst fit b. best fit, first fit, worst fit
c.worst fit, best fit, first fit d. None of these
6.With the FIFO page replacement policy, and enough space for storing 3 page frames, the memory page
reference string ‘ABCABDDCABCD’ would produce:
a.5 page faults b.6 page faults
c. 7 page faults d. 8 page faults
7.CPU scheduling decisions may take place when a process
a. Switches from running to waiting state b.Switches from running to ready state
c.Switches from waiting to ready d.All of the above
8. The DMA transfer is initiated by _____
a. Processor b. The process being executed
c.I/O devices d.OS
9.OS spends much of its time paging also instead of executing applications software, it is called………..
a.spooling b.formatting
c.thrashing. d.scanning
10.Which of the following option is true for virtual to physical address run-time mapping?
a. CPU b.Operating system
c. memory management unit d.PCI Each partition may contain
11.Each partition may contain ________ when memory is divided into several fixed sized partitions.
a. multiple processes at once b.exactly one process.
c.Two process d.at least one process
e. both a and b
12.Which process can be affected by other processes executing in the system?
a. cooperating process b.child process
c.parent process d. init process
13.In Unix, Which system call creates the new process?
a. fork b. create
c. new d. none of the mentioned
14. If all processes I/O bound, the ready queue will almost always be ______ and the Short term Scheduler
will have a ______ to do.
a. full, little b. full, lot
c.empty, little d. empty, lot
15.Which one of the following can not be scheduled by the kernel?
a.kernel level thread b. user level thread
c.process d. none of the mentioned
16.There are 10 different processes running on a workstation. Idle processes are waiting for an input event in
the input queue. Busy processes are scheduled with the Round-Robin time sharing method. Which out of the
following quantum times is the best value for small response times, if the processes have a short runtime,
e.g. less than 10ms?
a. tQ = 15ms b.tQ = 40ms
c. tQ = 45ms d. tQ = 50ms
17.All processes share a semaphore variable mutex, initialized to 1. Each process must execute wait(mutex)
before entering the critical section and signal(mutex) afterward.
Suppose a process executes in the following manner.
signal(mutex);
.....
critical section
.....
wait(mutex);

In this situation :
a. a deadlock will occur
b. processes will starve to enter critical section
c. several processes maybe executing in their critical section
d.all of the mentioned
18.To create a file ____________
a. allocate the space in file system b. make an entry for new file in directory
c.allocate the space in file system & make an entry for new file in directory
d. none of the mentioned
19.File type can be represented by ____________
a. file name b. file extension
c.file identifier d. none of the mentioned
20.Linux is an __________operating systems.
a.Open sourse b.Closed source
c.Microsoft d.Both A & B
FAZAIA BILQUIS COLLEGE OF EDUCTION FOR WOMEN

PAF Nur Khan, Rawalpindi

FINAL TERM EXAMS, FALL 2021

Marks
Subject: Operating Systems Class: BS(CS)
Subject Code: Time: 2 hr 40 mins Part-II 80
Semester: 5th (A & B)
NOTE: Please read all instructions carefully.
 You have 2hr 40 mins (Part-II) to finish the exam and submit it.
 Please avoid laconic answers so that we can understand you understood the concepts being
asked.
 The exam is close book.
 Solutions will be graded based on correctness and clarity. Each problem has a relatively
simple and straightforward solution. You may get as few as 0 points for a question if your
solution is far more complicated than necessary. Partial solutions will be graded for partial
credit.
 Understanding of paper is part of Exam.
 No choice, you have to attempt all Parts.

PART – II (20X4=80 Marks)

Question # 1: [20]
a. [5 Points] What are the requirements/conditions for the solution of critical-section problem?
b. Mutual Exclusion: Mutual Exclusion is a special type of binary semaphore which is used
for controlling access to the shared resource. It includes a priority inheritance mechanism
to avoid extended priority inversion problems. Not more than one process can execute in its
critical section at one time.
c. Progress: This solution is used when no one is in the critical section, and someone wants
in. Then those processes not in their reminder section should decide who should go in, in a
finite time.
d. Bound Waiting: When a process makes a request for getting into critical section, there is a
specific limit about number of processes can get into their critical section. So, when the limit
is reached, the system must allow request to the process to get into its critical section.

e. [ 4 Points] The following pair of processes share a common variable X..


Process A Process B
int Y; int Z;
A1: Y = X*2; B1: Z = X+1;
A2: X = Y; B2: X = Z;
X is set to 5 before either process begins execution. As usual, statements within a process are
executed sequentially, but statements in process A may execute in any order with respect to
statements in process B.
How many different values of X are possible after both processes finish executing
Sol : 4 times
Explanation: Here are the possible ways in which statements from A and B can be interleaved.
A1 A2 B1 B2: X = 11
A1 B1 A2 B2: X = 6
A1 B1 B2 A2: X = 10
B1 A1 B2 A2: X = 10
B1 A1 A2 B2: X = 6
B1 B2 A1 A2: X = 12.

.
f. [ 6 Points] A system has three processes (P1, P2, P3) and three reusable resources (R1, R2, R3).
There is one instance of R1, two instances of R2 and three instances of R3. P1 holds an R1 and
an R3 and is requesting an R2. P2 holds an R3 and is requesting an R1 and an R2. P3 holds two
R2 and an R3 and is requesting an R1. Draw the resource allocation graph wait for graph for the
sequences. And also mention whether it is a deadlock?Why?
Yes, a deadlock does exist. P3 is waiting for an instance of R1, the only
instance of which is held by P1 and P1 is waiting for an instance of R2, both
instances of which are held by P3. Since neither an instance of R1 nor that of
R2 will ever become available, hence, neither P1 nor P3 will ever be able to
continue executing. Therefore, a deadlock exists.

g. [ 5 Points] Given memory partitions of 100 KB, 500 KB, 200 KB, 300 KB, and 600 KB (in
order), how would each algorithm first fit , best fit and worst fit place processes of size 212 KB,
417 KB, 112 KB, and 426 KB (in order)?Which algorithm makes the most efficient use of
memory?

The first-fit algorithm selects the first free partition that is large enough to
accommodate the request.

First-fit would allocate in the following manner:

 212 KB => 500 KB partition, leaves a 288 KB partition


 417 KB => KB partition, leaves a 183 KB partition
 112 KB => 288 KB partition, leaves a 176 KB partition
 426 KB would not be able to allocate, no partition large enough!

b) Best-fit

The best-fit algorithm selects the partition whose size is closest in size (and large
enough) to the requested size.

Best-fit would allocate in the following manner:

 212 KB => 300 KB, leaving a 88 KB partition


 417 KB => 500 KB, leaving a 83 KB partition
 112 KB => 200 KB, leaving a 88 KB partition
 426 KB => 600 KB, leaving a 174 KB partition

c) Worst-fit

The worst-fit algorithm effectively selects the largest partition for each request.

Worst-fit would allocate in the following manner:

 212 KB => 600 KB, leaving a 388 KB partition


 417 KB => 500 KB, leaving a 83 KB partition
 112 KB => 388 KB, leaving a 276 KB partition
 426 KB would not be allowed to allocate as no partition is large enough!

d) Which algorithm makes the most efficient use of memory?

The best-fit algorithm performed the best of the three algorithms, as it was the only
algorithm to meet all the memory requests.

Question # 2: [20]
a. [5 Points ]In a paged segment system a virtual address consist of 128 bits of which 48 bits are
displacement, 44 bits are segment number & 36 bits are page no. calculate the following:
i. Page Size
ii. Max. Segment Size
iii. Max. No. of Pages & Segments

b. [5 Points] What is the purpose of device driver in managing I/O module and where the device driver
exist show with help of diagram.
Device Drivers are very essential for a computer system to work properly because without device driver
the particular hardware fails to work accordingly means it fails in doing a particular function/action for
which it has been created.
Device Drivers depend upon the Operating System’s instruction to access the device and performing any
particular action. After the action they also shows their reactions by delivering output or status/message
from hardware device to the Operating system.For Example a printer driver tells the printer in which
format to print after getting instruction from OS, similarly A sound card driver is there due to which 1’s
and 0’s data of MP3 file is converted to audio signals and you enjoy the music. Card reader, controller,
modem, network card, sound card, printer, video card, USB devices, RAM, Speakers etc need Device
Drivers to operate.
The following figure illustrates the interaction between user, OS, Device driver and the devices:

c. [10 Points] Consider a program consists of five segments: S0 = 600, S1 = 14 KB, S2= 100 KB, S3
=580 KB, and S4 = 96 KB. Assume at that time, the available free space partitions of memory are
1200–1805, 50 – 150, 220-234, and 2500-3180. Find the following:
i. Draw logical to physical maps and segment table?
ii. Allocate space for each segment in memory?
iii. Calculate the external fragmentation and the internal fragmentation?
iv. What are the addresses in physical memory for the following logical addresses: 0.580, (b) 1.17
(c) 2.66 (d) 3.82 (e) 4.20?
Question # 3: [20]
a. [10 Points] Construct Consider the following four processes to run in a single CPU. What is the
average waiting time when scheduling these processes according to FCFS, SJF, and SRTF? Also draw
Gantt chart.

1.draw gantt chart or time line for FCFS:


P1 P2 P3 P4
SJF
P1 8 unit P2 P3 P4
SRTF
P1 3 P2 3 unit P3 4 P4 6 unit

2. An operating system uses the Shortest Remaining Time first (SRTF) process scheduling
algorithm. Consider the arrival times and execution times for the following processes:
Formula for each algorithm average waiting time is : Total waiting time for P2 = Completion
time - (Arrival time + Execution time)
Also make table for each algorithms
b. [10 Points] Consider the following page reference string:
1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6.
How many page faults occur for the following page replacement algorithms assuming one, three,
four, five, six, or seven frames? Assume that all pages are initially used by pages left over from
another process, so your first unique pages will all cost one fault each.

a. LRU replacement
b. FIFO replacement
c. Optimal replacement

LRU:
d. 3 frames:
e. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
f. Frame 1: 1 4 5 1 7 2 -
g. Frame 2: 2 - 6 3 - -
h. Frame 3: 3 1 2 - 6 1 6
i. 15 faults
j.
k. 4 frames:
l. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
m. Frame 1: 1 - - 6 -
n. Frame 2: 2 - - - - -
o. Frame 3: 3 5 3 - -
p. Frame 4: 4 6 7 1
q. 10 faults
r.
s. 5 frames:
t. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
u. Frame 1: 1 - - -
v. Frame 2: 2 - - - - -
w. Frame 3: 3 6 - -
x. Frame 4: 4 3 - -
y. Frame 5: 5 7
z. 8 faults
aa.
bb. 6 frames:
cc. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
dd. Frame 1: 1 - - -
ee. Frame 2: 2 - - - - -
ff. Frame 3: 3 - - -
gg. Frame 4: 4
hh. Frame 5: 5 7
ii. Frame 6: 6 - -
jj. 7 faults, which is the fewest we can have with 7 pages
kk. FIFO:
ll. 3 frames:
mm. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
nn. Frame 1: 1 4 6 3 - 2 - 6
oo. Frame 2: 2 - 1 2 - 7 1
pp. Frame 3: 3 5 1 6 3
qq. 16 faults
rr.
ss. 4 frames:
tt. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
uu. Frame 1: 1 - 5 3 - 1
vv. Frame 2: 2 - 6 7 3
ww. Frame 3: 3 2 - 6 -
xx. Frame 4: 4 1 2 -
yy. 14 faults
zz.
aaa. 5 frames:
bbb. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
ccc. Frame 1: 1 - 6 - -
ddd.Frame 2: 2 - - 1 -
eee. Frame 3: 3 2 - -
fff. Frame 4: 4 3 - -
ggg.Frame 5: 5 7
hhh. 10 faults
iii.
jjj. 6 frames:
kkk. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
lll. Frame 1: 1 - - 7
mmm. Frame 2: 2 - - - - 1
nnn.Frame 3: 3 - - 2
ooo.Frame 4: 4 3
ppp.Frame 5: 5
qqq.Frame 6: 6 - -
rrr. 10 faults
sss. Optimal:
ttt. 3 frames:
uuu. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
vvv.Frame 1: 1 - - 3 - -
www. Frame 2: 2 - - - 7 2 -
xxx.Frame 3: 3 4 5 6 - 1 6
yyy. 11 faults
zzz.
aaaa. 4 frames:
bbbb. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
cccc. Frame 1: 1 - - 7 1
dddd. Frame 2: 2 - - - - -
eeee. Frame 3: 3 - - -
ffff. Frame 4: 4 5 6 - -
gggg. 8 faults
hhhh.
iiii. 5 frames:
jjjj. 1, 2, 3, 4, 2, 1, 5, 6, 2, 1, 2, 3, 7, 6, 3, 2, 1, 2, 3, 6
kkkk. Frame 1: 1 - - - -
llll. Frame 2: 2 - - - - -
mmmm. Frame 3: 3 - - -
nnnn. Frame 4: 4 7
oooo. Frame 5: 5 6 - -
pppp. 7 faults, which is the best we can do
Question # 4: [20]
a. [10 Points] Consider a user program of logical address of size 6 pages and page size is 4 bytes. The
physical address contains 300 frames. The user program consists of 22 instructions a, b, c, . . . u, v .
Each instruction takes 1 byte. Assume at that time the free frames are 7, 26, 52, 20, 55, 6, 18, 21, 70,
and 90.
Find the following?
A) Draw the logical and physical maps and page tables?
B) Allocate each page in the corresponding frame?
C) Find the physical addresses for the instructions m, d, v, r?

b. [10 Points] A virtual memory system has the following specification:


Size of the virtual address space=64k
Size of the physical address space=4k
Page size=512
i)find all the virtual addresses that will generate a page fault and compute the main memory
addresses for the following virtual addresses. 24,3784,10250,30780
Virtual physical
page# frame#
0 0
3 1

_ Good Luck _ 7
4
2
3
10 4
12 5
30 6
31 7

You might also like