0% found this document useful (0 votes)
20 views7 pages

cs330 Endsems 2023

Uploaded by

aatmanjn
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)
20 views7 pages

cs330 Endsems 2023

Uploaded by

aatmanjn
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
You are on page 1/ 7

End-Semester Examination

CS330: Operating Systems


Department of Computer Science and Engineering
Total marks: 70 Duration: 150 minute

Roll No: al035S Signature:

The exam is open books, notes, printed materials, No electronic device should be used during the
examination. Consulting/discussing with anyone during the exam is strictly prohíbited. Unless specified
etplicitly, assume 64-bit X&86 architecture with multiple CPUs and an 05 uith no bugs
Best of luckl

DO NOT WRITE ANYTHING IN THIS AREA

Q16 Q2 Q3 O Q4

5 245
Q5
6 Q6 Q7 TOTAL

to mark all coTTect choices to get


1. Select the correct answer(s) for the following questions. Note that, you have 3×5 =
the credits (no partial marks). No explanation required.
(a) Which of the following file related system call(s) can not always be served without performíng any dísk
a file system that caches only
I/0before returning to user space after their successful execution? Assume block.
bitmap, inodes and the super
the disk blpcks corresponding to the inode bitmap, block usage
A. lseek
(B) open a file
open with 0_CREAT (i.e., create a file)
D. read 8192 bytes from the beginning of a file of size 1MB
(E) Write 8192 bytes at the end of the fle of size 1MB
between the number
(b) Execution of fsck utility for a given file system before mounting revealed a mismatch that, the fle
of data blocks calculated from the data block bitmap and all inode data pointers. Assume
the
system was consistent and fully persisted to disk just before the last on-going operation during which
system crashed. The last on-going operation can be
A. creation of an empty file or directory
B. truncation of a file (deleting file content)
C. write to an existing block of a file (update operation)
write to the end of the file (append operation)
E deletion of a file or directory
(c) Consider the following pseudocode.
sem_t S1, S2, s3; /* All initialized to zero */
string ){ number (){
wait (S1); printf ("1");
printf ("A"); post (S1);
wait (S2); printf ("2");
printf ("B"); post (S2);
wait (S3); printf ("3");
printf ("C") ; post (S3) ;

Which of the following is/are possible output (s) if one thread executes string () and the other thread
executes pamber) concurrently?
1A2B3C
B. lAB23C
e123ABC
D. 12ABC3
E. 12A3BC
(d) Assuming
Consider two threads T; and T; of a process P ereated using the pthread API in the Linuz syaten
X86 system with split-mode addressing, which of the following statement(s) is/are false.
A. If T is in kerncl mode, T, is not nllowed to enter the kernel mode
BThe kernel stack used by T and T; are different
C.)The OS page fault handler must handle the page faults caused by TË and T; in a serial manner.
D. When the OS scheduler performs a context switch between T; and T2, the page table base pointer
(CR3) register is not changed
IWhen the OS scheduler perform8 acoutext switch between T and P,the page table base pointer
(CR3) register is changed
(e) Consider that there is a page fault or virtual address V of a multi-threaded process orn a singe CPU
system. When the OS page fault lhandler inspects the page table mappings, it finds that the page tabie
entries are correct for all the levels before the leaf Jevel, Note that, the leaf level is the level-4 PTE in a
4-level page table where the page table base register (e... CR3 in X86) points to the level-1 PTE, In the
leaf-level page table entry (PTE),
A, the present bit can be zero
B. the present bit can be one
O the write bit can be one (both read-write allowed)
D. the content can be correct in all aspects if interrupts are disabled during page fault handling
E) the content can be correct in all aspects if interrupts are enabled during page fault handling
2. True or False with justification. Justification should be a precise argument supporting your verdict. No marks2x5= 10
without proper reasoning.
(a) Physical memory usage of a system will decrease on successful execution of the exec systen call.

tase ese cw be fino Catel, tue can le tte att

heeee eenaro can e whe he

(b) If a file system always performs non-cached I/O, there will be no consistency issues.

.5 False dish ad eonntty mawehale tees bebmeem


Calent be comneeled a

code can be swapped out.


(c) Any physical memory frame containing the OS
bt i he
bue, Swmee we ane mai n alng

never result in
sequence, LRUand Belady's optimal (MIN) page replacement will
(d) For any memory access
the FIFO page replacement.
more number of page faults than
L,2;3, Ly 4, 2,3 ’ LRU
False, o #frowes =3 md seqene
2
(e) Afull TLBfAush is necessary during aprocess context switch.

Falee, he same TB

and a page size of four kiotytes.


in a system with fve levels of page table
3. Consider the following code fragment
int d_calc (int a, int b){
register int ctr = 0;
while (ctr < a){
b t* a;
ctrt+;

return b;

registers)
1/Disassembly (R1, R2, R3 and A are
b' -->R2
argument 'a' --> R1 and
//function d_calc,
.function d_calc ('ctr'--> R3)
Oxx7FFO01080000: mov $0, R3 //Load R3 with zero
//Comparectr' with 'a'
Ox7FFO01080004: cmp R3, R1 0x7FFO010800018 if ctr' >= 'a'
Ox7FFO01080008: jge (+0xC) //Jump to += 'a')
//Add R2 = R2 + R1 ('b'
Ox7FFO0108000C: add R2, R1 7/Increment counter ('ctr'++)
Ox7FFO01080010: inc R3
//Jump to 0x7FF001080004 value)
Ox7FFO01080014: jmp (-0x14) register A (return
Ox7FF001080018: mov R2, A /7 mov R2 to the
Ox7FF00108001C: ret 1/ Return
executed in one
and only the above function is +2=1
execution
page faults during theAnswer the following questions. |2 +3 + 2 +2
Assume that there are no context switches.
scheduling interval without any final answer)
mention the calculation steps along with the mnemory accesses to perforn
address trans
(Briefly be the number of
TLB support, what will
(a) In a MMU with no executed?
100) is
lation if d_calc (0,

trans
memory accesses to perform addre ss
TLB support, what will be the number of
(b) In a MMUwith no 100) is executed?
lation if d_calc (5,

42=11
tatal beteh= sx3
(c) Write an expression for the number of memory accesses to perform address traslation in terms of a and
bfor a MMUwith no TLB (no explanation required).
2

() What will be the minimum number of menory accesses reauired to performaddress trarslation if dcalc(5,
100) is executed for a MMUwith a TLB (a8sUming an emptyTLB at the start of the function)? 2
loo-s)
(41) XS 3

(e) Write an expression for the minimum number of memory accesses required to perform address translation
in terms of a and b for a MMU with a TLB (assuming an empty TLB at the start of the function, no
explanation required). 2
Il+ 3(4-) t2 = 344 |0
4. Consider the following implementation as a solution to critical section problem for two threads To and T.
int flag [2] = {0,0};
int turn = 0;
void lock (int id) /*id = 0 or 1 */

flag [id] = 1;
while(flag [id 1] && turn == (id 1)); /* is the bit-wise XOR*/

void unlo ck (int id)

turn = id 1; // (1)
flag [id] = 0; // (S2)

Does the above implementation guarantee mutual exclusion? If yes, provide a formal argument for
corTectness.
If not, show a concrete example when the mutual exclusion is violated.

yhe oltis
loek to aher
he mportant aut to nati here uthst roth tL (mdtti
sther hand bnda badh to be crd he oder to koy
hebots to conteatatel, onteat awieh halos oller

oatuginny ternn lody thenthe nstited


concurrently Assurne
which is executed by three threads T. T; and Tz
5. Consider the following pseudocode
atomic.
that, the pointer assignment at line #5 is
shared across threads
1. int *ptr = NULL; //Global,
the semaphore S with value 0
2. sem_init (S, 0); //Initialize
3. void process (){
4. if(!ptr) {
ato
5. ptr = malloc (sizeof (int));
*ptr = 0;
6.
7.
sem_post (S);
8.
sem_wait (S):
9.
sem_wait (S) ;: ato wme
10.
omic_inc (ptr) ; // Atomically increment (*ptr)
11. at
sem_post (S);
12.
sem_post (S);
13.
14. } 6+ 1.5 +l.5 =
threads. The
the following questions. line numbers for the deadlocked different line
Answer the
scenarios along withinterleaving deadlocked at
down all unique deadlock the (i.e., threads
(a) List scenario is based on interleaving).
uniqueness of the deadlock participating in the same
of threads
numbers, not permutations

0T allocated
to lie 4 ngw
lie 4.
ad hewee ane at dead loek
is allocatel
helßened to B md
crndent uiteh ad t ereuted
Busfeled fo luie|0. atsamne
at viA deadloee
(b) If all threads complete without any deadlock, what will be the minimum number of nalloc cals lat s
#5) and why?
Minimww nmbr malleo calll wl be2 eisce
to osss lme qd o we wee s22 nud pen-bl are by

(c) If all threads complete without any deadlock and print the value of ("ptr) at the end of the
will be the minimum value of ("ptr) (across all function, what
possible execution orders) and wy 15

he muw male

tbenyh ll1)2 tne ht


and lanto is etumed made i stt Hrck thw O
Kast sritmy threud cawt ae
6. Consider an indexed ile systemkound in the UNIX merement hewee L
operating system. The inodes have an indexed allocation
scheme as follows: eight direct block address, four single-indirect block address and two
addresses. Assumethat, the block size and on-disk inode size are one kilobyte (1KB) and double indirect block
Block address in the system is 4 bytes long. Further, assume that every 256 bytes, respectívely.
directory entries having the following structure, directory maintains an array of ffat

struct dentryl
u32 inode-number ;
char mame [252]:

Assume that the disk I/O operations are performed in units of block size i.e., 1KB. Answer the following
questions (no explanation required). |1+1+3+3=8
(a) What is the maximum disk size supported by the file sxstem?
42

(b) You have written a program to create as many files as possible under an initially empty directory. How
many files your program can successfully create?

4
A user process opens and successfully reads an existing file at /h ome/user/courses/os/notes . txt of size
one kilobyte, where / is the file system mount point. Asume that, the super block, all the inodes and
index meta-data required to access the file and directory are present in memory. What is the minimum
and maximum number of disk block accesses required to complete the read operation?
(d) In the above
(with the pathquestioh,
sane as
assme thst the fle otes t t is o sie 1MB and e
(offset is a msltiple of 1KB)
ptevios qeto), sfter that i readie one Bock (1KB)
the prosopens the fle
at # randont blncke offet
cached. However, the fle stessfelly, Frshe see hat. the siper 5linrlk all inedes are always
dizectory are not cached. indesesisand ditectory COnten hery o y Be esched Data blncks of fle as
complete the read operaton?Whst the minimom and maYi sby of dilk Block aeeeeses pnnied to

7. Memory is a precious resource and you want to augment the virtual mermoty subeystem of the 05 to compr the
Lsed physical memory to increase the degtee of multiprog amming withost ing swapping Assme that there
3an existing compression logic in the O8 which provides funetionalities lilke commpresion á deeompesion
Specifically, you can axSumethe followáng two OS level funetions are already noable,
int compressPFN (u32 srcpfn, void *outPTR):Compresses 4096 bytes of data in the page frame srcpfs and
stores the compressed stream into outPTR. The length of compressed data is returned by this funetio
void decompressPFN (void *inPTR, u32 dstpfn, u32 size): Decompresses conpressed data of length =
size stored at inPTR and stores the decompressed data in the dstpfn. The caller of this funeticn shonldcasure
that the decompressed data is of length 4096 bytes.
The solution framework is as follows: There is a background user space process (a daemon, sy capserr vhich
invokes a new system call i.e., compress in a periodic manner. The design of compress system call (paraeters
tãe
return value and implenentation) is to be discussed as part of the answer. You are required to disess
implementation of the compress system call-both the mechanisn and policy.
effects on other OS
Mechanism: How exactly the compress system call is implemented? What are the sideYour implementation
handling them.
subsystems (like virtual memory etc.) and your proposed methods of
should handle both correctness and efficiency.
questions like which memory pages to compress,
Policy: In this part, you are required to discuss answers to resource tradeof?
time etc. Note that, you should discuss the
how many memory pages to compress at what
savings.
implications of yyour policy e.g., CPUusage vs. memory Assume page size
memory pages because of performance reasons.
Hint: you may not want to compress all the
of 4KB and X86 like paging support.
ador ttual adls

utni call tiv


hente oll be hew the Cuteud
the
emy ll
Cowres alla the ident
be don
(ahrocnpast.

You might also like