You are on page 1of 8

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI – K. K.

BIRLA GOA CAMPUS, First Semester 2022-2023


Course Title: OPERATING SYSTEMS Course No CS F372 Marks: 114
Component: Comprehensive [Closed Book] Date: 21/12/2022 Max.Time: 180min
Make Index Page [Will not be evaluating if page number is not in INDEX].
Start every main question [Q1, Q2 …. Q11] in a fresh page.
Question #1 [15 Marks]
Analyze the C code given below. All the operations are successful. Find the following:
(A) How many new process the C code will create?
(B) How many new threads each process will create (because of pthread_create)?
(C) Draw the tree diagram of the processes (mention number of threads each
process create) showing all parent child relationships.
(D) Find the final values of variable x and y in each process.
int x, y ; void *fun(void *args)
int main( ) { x +=15; y - = 10;
{ int i; pthread_exit(0);
pthread_t tid; }
x = 10; y = 5;
for ( i = 0 ; i < 2 ; i ++ ) void *fun1(void *args)
{ { x - =5; y + = 5;
y = x + 5 ; x = y ++ ; pthread_exit(0);
if (fork( ) ) }
{
pthread_create(&tid, NULL,fun,NULL);
pthread_join(tid,NULL);
x - = 1; y + = 5;
}
if( ! fork ( ) )
{ x+=5; y+=7;
execl ( “/bin/ls” , ”ls” , 0 ) ;
pthread_create(&tid, NULL,fun,NULL);
pthread_join(tid,NULL);
}
pthread_create(&tid, NULL, fun1, NULL);
pthread_join(tid, NULL);
}
return 0 ;
}

(A) 9
(B) 9
(C) And (D)
P0 (4 children – P1, P2, P3, P4) Final value 40, 30 [4 threads]
P1 (3 children – P5, P6, P7) Final value 26, 16 [3 threads]
P2 (No children) Final value 35, 17
P3 (1 child – P8) Final value 26, 35 [1 thread]
P4 (No children) Final value 50, 32
P5 (No children) Final value 21, 22
P6 (1 child – P9) Final value 12, 21 [1 thread]
P7 (No children) Final value 36, 18
P8 (No children) Final value 36, 37
P9 (No children) Final value 22, 23
Question #2 [4M + 2M + 4M = 10 Marks]
Assume a memory management module supporting BUDDY system for the placement of
1 MB memory. Allocate the following requests [the requests are coming one after the
other in the same order]. Clearly mention all the requests which you could not allocate.
Request 1: Allocate 65KB Request 7: Allocate 300KB
Request 2: Allocate 10KB Request 8: Allocate 36KB
Request 3: Allocate 80KB Request 9: Allocate 62KB
Request 4: Allocate 130KB Request 10: Release 80KB [Allocated by request 3]
Request 5: Allocate 160KB Request 11: Allocate 150KB
Request 6: Release 130KB [Allocated by request 4]
After finishing all the requests
(1) Draw the final tree representation of the BUDDY system [After Request 11].
(2) Find the total free space available in the system for allocation
(3) Find the total internal fragmentation caused because of all the allocations.

(1) [0-128K] R1, [128K – 144K] R2, [192K – 256K] R8, [384K – 448K] R9, [512K – 768K] R11,
[768K – 1M] R5

(2) 240KB

(3) 301KB

Question #3 [2M + 4M + 5M + 5M + 4M + 5M = 25 Marks]


A Computer system consists of TLB, Main Memory (MM) and Disk (as virtual storage).
The system has 42 bit virtual address and 34 bit physical address. The frame size of MM
is 8KB. The system follows hierarchical paging. One entry in inner most page table is
4bytes long and the entry size doubles in each level from inner most to outer most.
(A) Divide the address.
(B) What should be the number of frames required in MM, if you what to store the largest
possible program and all its page tables in the MM? (mention frames required for
each component
(C) If the process is of 256 MB size, what will be the total number of frames required in
MM to hold program & all its page tables in MM? (mention frames required for each
component)
(D) If the system with 34 bit physical address is following inverted page table with an
entry size of 16 bytes, what will be the total number of frames required in MM to hold
2MB program and its page tables in MM? (mention frames required for each
component)
(E) Assume the TLB has 64 fully associative locations and it follows LRU replacement
strategy. What will be the size of TLB if the number of bits used for protection is 5?
(F) What will be effective access time of the process if it has 100000 memory accesses
out of which 90000 are TLB hit. Assume TLB access time is 2nS, MM access time is
100nS and OS overhead is 20nS?

(A) 8, 10, 11, 13


(B) 1 + 28 + 218 + 229
(C) 1 + 1+ 16 + 215
(D) 32 MB + 2 MB
(E) (29 + 21 + 1 + 5 + 6) * 64 [page#, frame#, v/i, protection, LRU]*#blocks
(F) 100000*(2+100) + 10000(2+20+(3*100)) = 100000*102 + 10000*322
Question #4 [3M + 2M + 2M = 7 Marks]
Assume an Intel like architecture supporting both segmentation and segmentation with
paging. The architecture has the following specifications:
(1) Segment can be maximum of 64GB size
(2) There exist Local and Global descriptor tables. Each descriptor table should not
exceed 16KB size. Each entry in descriptor table is 16B long.
(3) Logical address uses 4 bits for protection and 1 bit to decide whether the
descriptor is global or local.
(4) Number of bits in linear address will be the same as the number of bits in logical
address.
(5) The system supports 2 different page sizes of 32KB and 128MB. Each entry in
page table is 8B long in all levels of hierarchy.
(A) What is the minimum number of bits required for segment selector and offset
of logical address?
(B) What is the linear address division for paging with 32KB page size?
(C) What is the linear address division for paging with 128MB page size?

(A) 15, 36
(B) 12, 12, 12, 15
(C) 24, 27
Question #5 [5 Marks]
Assume a main memory having 16 frames. The individual process page tables are given
below. The administrator wanted to change the page table model into inverted page table
model. Construct inverted page table from the given process information
[P0] pid = 20 [P1] pid = 28 [P2] pid = 12 [P3] pid = 31 [P4] pid = 16
Frame# v/i Frame# v/i Frame# v/i Frame# v/i Frame# v/i
3 V 14 V 3 i 2 V 7 V
12 I 5 V 8 v 1 V 12 V
11 V 7 I 15 i 11 I 1 I
5 I 9 I 0 v 10 V 9 V
13 V 15 V 4 v 7 I 6 V

Single table consists of 16 entries. Each entry will have pid and page number in it
Pid Page #
12 3
31 1
31 0
20 0
12 4
28 1
16 4
16 0
12 1
16 3
31 3
20 2
16 1
20 4
28 0
28 4

Question #6 [5 Marks]
Consider the following snapshot at time t. Draw wait for graph. Does the system enter
into deadlock [Yes/No]? Explain.
Process Data Data items the Process Data Data items
items process is items the process
locked waiting for locked is waiting for
P1 X2 X1 P5 X1, X5 X3
P2 X3, X10 X7, X8 P6 X4, X9 X6
P3 X8 X4 P7 X6 X5
P4 X7 X1

P1  P5, P2 P3, P2  P4, P3  P6, P4  P5, P5  P2, P6  P7, P7  P5


Deadlock exists as there exist cycles and all the resources are single instance resource.

Question #7 [4 + 6 = 10 Marks]
Consider the following snap shot of the system of five processes P0 to P4 and 5 resource
types, A, B, C, D and E. The total instances of A, B, C, D and E in the system are 10, 17,
10, 13 and 11 respectively.
Processes Maximum Claim Need
A B C D E A B C D E
P0 9 13 10 7 8 7 11 8 5 8
P1 4 9 7 5 5 3 7 6 3 3
P2 7 13 5 10 10 6 11 4 8 10
P3 1 5 1 3 5 1 3 1 1 3
P4 5 8 5 5 9 3 6 4 5 5
(A) Determine if the system is in the safe state. If yes, give the safe sequence and
other relevant matrices.
(B) If process P0 requests (0, X, Y, Z, 0), then determine the maximum values of X, Y
and Z which can be granted without making the state unsafe.

Answer
ALLOCATION
Process A B C D E
P0 2 2 2 2 0
P1 1 2 1 2 2
P2 1 2 1 2 0
P3 0 2 0 2 2
P4 2 2 1 0 4
AVAILABLE
4 7 5 5 3

Safe sequence P3, P4, P1, P2, P0 (Only one safe sequence possible)

(A) If process P0 requests (0, X, Y, Z, 0), then determine the maximum values of X, Y and Z which
can be granted without making the state unsafe.
X2 Y0 Z1

Question #8 [9 Marks]
Write a monitor for Reader – Writer problem. The monitor should have the following
functions – Writer_Entry, Writer_Exit, Reader_Entry, Reader_Exit. Use minimum
number of condition variables.

Monitor
{
Writer_Entry()
{ if((read_count>0) || (write_count>0)) wrt.wait;
write_count=1;
}
Writer_Exit()
{ if(read>0) rd.signal;
else wrt.signal;
}
Reader_Entry()
{ read++;
if(write_count==1) rd.wait;
read_count++;
rd.signal;
}
Reader_Exit()
{ read - -;
read_count - -;
if(read_count==0) wrt.signal;
}
Initilize()
{ read_count=0; write_count=0; readd=0;
}
}
Question #9 [6 Marks]
If initial value of shared variable x is 0, find the maximum and minimum x value
possible when T1 and T2 are executing concurrently. Write the sequence in which this
occurs.

T1 T2
int i; int i;
for ( i = 0; i < 100; i + + ) for ( i = 0; i < 100; i + + )
{ x = x + 1; { x = x + 1;
x = x – 1; x = x – 1;
x = x + 1; }
}

Max : +300 Min: -199

Question #10 [11 Marks]


Consider a system having three concurrently running threads T1, T2 and T3. The
threads should execute critical section in the given order repeatedly. T1 starts running
first and it runs for 2 times [T2 and T3 cannot access critical section until T1 finishes
executing in critical section twice]. Once T1 completes executing twice in critical section,
T1 blocks itself after allowing T2 to execute in critical section. After T2 finishes its
critical section, T2 allows T3 to execute in critical section. T2 and T3 repeatedly execute
thrice before blocking themselves and allowing T1 to start the cycle again. The resultant
sequence of execution should be as below:
P1, P1, P2, P3, P2, P3, P2, P3, P1, P1, P2, P3, P2, P3, P2, P3 ……..
Write solution (pseudo code only) for the problem using counting semaphores [Assume
that the semaphore implementation follows semaphore.h header file]. Mention initial
value of all the counting semaphores and variables used. The answer should be of the
following structure.
// Pseudo code for initializing all the global semaphore variables

// Thread T1 // Thread T2 // Thread T3

//Initialization if required //Initialization if required //Initialization if required


while (1) { while (1) { while (1) {
//0 or more code here //0 or more code here //0 or more code here
CS CS CS
//0 or more code here //0 or more code here //0 or more code here
} } }
// Pseudo code for initializing all the global semaphore variables
semaphore sem1  1; semaphore sem2  0; semaphore sem3  0;

// Thread T1 // Thread T2 // Thread T3


int var_T1=0; while (1) { int var_T3=0;
while (1) { while (1) {
wait (sem2);
wait (sem1); wait (sem3);
CS CS CS
var_T1++; var_T3++;
if(var_T1 == 2) signal (sem3); if(var_T3 == 3)
{ var_T1=0; { var_T3=0;
signal (sem2); signal (sem1);
} }
else } else
signal (sem1); signal (sem2);
}
}

Initialization: 1M
Thread 1: 4
Thread 2: 2
Thread 3: 4

Question #11 [12 Marks]


Consider the following snapshot at time t in a Uniprocessor system. Process P goes for x
units of I/O operation after every y units of execution is represented as xPy.
Total Execution
Process Arrival time xPy
time
A 0 8 2A6
B 2 5 5B2
C 3 5 CPU bound
D 6 7 4D4
Find the resultant schedule and represent it as Gantt chart with Virtual Round Robin
scheduling algorithm. Consider the time quantum of 4 units. Find the normalized turn-
around time and waiting time for each process.
7 Marks

Start time End time Process


0 4 A
4 6 B
6 10 C
10 12 A
12 14 B
14 16 A*
16 20 D
20 21 C*
21 22 B*
22 24 IDLE
24 27 D*
Process TAT N.TAT WT
A 16 2 (16-8-2) = 6
B 20 4 (20 – 5 – 10) = 5
C 18 3.6 (18 – 5 – 0) = 13
D 21 3 (21 – 7 – 4) = 10

You might also like