OS Final Spring'24
OS Final Spring'24
Karachi Campus
a) Consider a tcke booking sysem where he available number o tckes or
each program mus be mainained. A person who wishes o book a tcke calls
he bookTicke() uncton, which checks i tckes are available and hen
decreases he available tckes coun by one. This is illusraed in he code
shown. Now explain how a race conditon is possible in his siuaton. Also,
show a Phread library-based C program ha avoids race conditon using a muex. [1 + 3]
b) Explain synchronizaton issue(s) in producer and consumer in a producer-consumer problem. Wrie and explain C code
snippes ha use wo ypes o semaphores as a soluton or his problem. [2+2]
d) How busy waitng is implemened during synchronizaton? Wrie wo C code snippes showing wo dieren mehods.
Also, explain he working o any one snippe using a dry run wih variable values. Assume wo processes where one
is executng in is critcal secton and oher is waitng [2 + 1].
Q2. [15 marks] Instruction: Write answers as bullets points. Make suitable assumptions, if needed.
a) Explain exernal ragmenaton in main memory using a labeled diagram. Wha causes inernal ragmenaton in a
page? Explain wih an example. [2 + 1]
c) LRU is one o he many page replacemen algorihms. Explain is wo implemenatons as ollows:
i. Use a labelled diagram and sepwise hins o describe clock (second chance) algorihm. Show i does approximae
LRU unctonaliy. [2]
ii. Now, enhance he above algorihm o ensure ha diry victm pages are ushed o memory beore reuse. [2]
d) Suppose a program is accessing main memory in a virual memory sysem having a page size o 2K.
i. Sae he dierence beween paged and demand paged memory sysem? [1]
ii. Show a labelled diagram which show how a virual memory address generaed by a program is ranslaed ino a
physical address. Now, in your diagram, assume suiable values or page number and page ose and show how he
processor calculaes he physical address. [3]
CLO # 1 - Describe, discuss, and analyze, services provided by the modern Operating Systems.
a) Creae a diagram illusratng he inerrup handling process in a ypical operatng sysem. Wha is he purpose o
tmer in operatng sysems and how i is relaed o inerrups. [1+2]
b) Describe executon seps o a (generic) sysem call using wo modes in a modern operatng sysem wih he help o
a labelled diagram. Wha problems do you expec i OS execues his sysem call in user mode only? Explain. [2+1]
CLO # 2 - Understand, design, and implement solutions employing concepts of Processes and Threads
Q4. [6 marks]
a) Consider Google’s Chrome browser as a mult-process archiecure. Wha bene would his implemenaton
provides o he user? [2]
b) Show how many processors are needed o gain a 3.5 tmes speedup i he serial porton is 20%. [2]
c) Explain dieren ypes o mapping beween user-level and kernel-level hreads. [2]
a) Consider Linux Compleely Fair Scheduler. Explain: i) he compuatons done o akes scheduling decisions, and ii)
give a diagram o show how CFS ecienly compues he nex runnable ask. [2+2]
b) Assume an Operatng Sysem uses FCFS scheduler. Suppose here are only wo processes: rs is running wih fy
hreads o compue he value o Pi using 5000K ieratons, and he second process is an Inerne browser where a
single ab is shown o he user. Explain how you change he code o frs process such ha he FCFS scheduler run
boh processes alernatvely in his case. Write precise answer in 2-3 lines only [2].