Que Stio N No Type (MC Q/SAT) CO Mapp Ing Answer Key

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 24

(For all courses having end semester Full Mark=50)

KIIT Deemed to be University


Online End Semester Examination(Autumn Semester-2021)

Subject Name & Code: Operating Systems and CS-2002


Applicable to Courses: B.tech. 4th Sem

Full Marks=50 Time:2 Hours

SECTION-A(Answer All Questions. Each question carries 2 Marks)


Time:30 Minutes (7×2=14 Marks)

Que Question Question CO Answer Key


stio Type(MC Mapp
n Q/SAT) ing
No
Q. Which one of the following is not CO3 (a)
No: shared by the threads of the same
1 process?
(a) stack
(b) address space
(c) file descriptor table
(d) message queue
Which of the following may block CO2 e
running process?
(a) fork
(b) read
(c) down
(d) both fork and down
(e) all
Assume that 3 processes all with CO4 c
requirements of 1 second of CPU time
each and no I/O arrives at the same
time. What will be the Avg. time to
completion for the processes if R-R
CPU scheduling is used with 0.1 sec
time span and assume no overhead for
context switch.
(a) 2.5 sec
(b) 2.15 sec
(c) 2.9 sec
(d) 3 sec
If fixed priority scheduling is used in CO4 a
different queues in multilevel queue
scheduling then
(a) Starvation can occur
(b) Starvation cannot occur
(c) All the queues will get almost fair
chance
(d) none of these
Q. Which of the following disk CO6 b
No: scheduling strategies is likely to give
2 the best throughput?
(a) Farthest cylinder next
(b) Nearest cylinder next
(c) First come first served
(d) Elevator algorithm
Let an instruction takes i ms and page CO3 c
fault takes an additional j ms. If the
avg. page fault occurs after k
instructions, the effective instruction
time will be,
(a) i+j*k
(b) (i+j)/k
(c) i+j/k
(d) i+2*j/k
What will be the minimum RAM size CO5 b
so that the following program can
run?

(a) 16 kb
(b) 15 kb
(c) 14 kb
(d) 17 kb
Consider the following page reference CO5 a
string: 7, 6, 5, 4. 7, 6, 8, 7, 6, 5, 4, 8. If
MRU (most recently used) page
replacement technique is used, then
what will be the difference of page
faults in case of memory with 4 and 3
frames are used respectively. Assume
initially, frames are empty.
(a) 0
(b) 1
(c) 2
(d) 3
Q. If a CPU generates address 00f2 and CO5 a
No: re-locatable register contains ff22
3 then what will be the physical
address?
(a) 10014
(b) 10024
(c) fc224
(d) ff243
Which of the following is false in CO3 b
context of inter process
communication?
(a) communicate with each other
(b) share same address space
(c) synchronize their actions
(d) passing message with each other
CO5 b

(a) 8
(b) 7
(c) 10
(d) 13
Suppose the to service a page fault is CO5 c
on average 20 ms, while a memory
access takes 10 micro seconds. Then
80% hit ratio results in avg. memory
access time of
(a) 3008 micro sec.
(b) 5004 micro sec.
(c) 4008 micro sec.
(d) 2008 micro sec.
Q. If time span size is 3 unit of time and CO3 a
No: only one process with 16 burst time is
4 there in ready queue, then we apply R-
R CPU scheduling algorithm. What
will be the number of context switch?
(a) 5
(b) 6
(c) 4
(d) 7
A process executes the following CO1 d
segment of code: for(i=1; i<=n; i++)
fork(); The number of new processes
created is:
(a) n(n+1)/2
(b) n
(c) 3^n-1
(d) 2^n-1
Consider the following statements: CO2 d
S1: CPU is a non preemptive resource
S2: I/O device is preemptible
Which of the above statements is/are
true?
(a) S1
(b) S2
(c) both are true
(d) none of these
A company has hired you to design CO5 a
the virtual memory system for their
new line of desktop computers. Each
computer will have 32 bits virtual and
physical addresses, and memory will
be allocated in pages of size 2KB. How
much physical memory is required to
store the page table?
(a) 2MB
(b) 4MB
(c) 6 MB
(d) 3 MB
Q. Consider 4 processes sharing the CPU CO3 b
No: in a round-robin fashion. Assuming
5 that each process switch takes 1
second, what must be the quantum
size q such that the overhead resulting
from process switching is minimized
but at the same time each process is
guaranteed to get its turn at the CPU
at least every 10 seconds?
(a) 3
(b) 2
(c) 1
(d) 4
Consider the following cooperating CO4 d
processes p1 and p2 using shared
variable i = 11
Method Used by P1
begin
A

i++;
printf(“%d”,i);
end
Method Used by P2
begin
printf(“%d”,i);
B

end
Write the code for A and B so that
output will be 9 10.
(a) S = 0, A: Signal(S), B: Wait(S)
(b) S= 1, A: Signal(S), B: Wait(S)
(c) S = 0/1, A: Signal(S), B: Wait(S)
(d) none of these
A counting semaphore has a value of CO4 a
(-8) in a certain period. So, what is the
number of waiting process (es)?
(a) 8
(b) 7
(c) 9
(d) none
At a particular time of computation CO4 a
the value of a counting semaphore is
7.Then 20 P operations and 14 V
operations were completed on this
semaphore. The resulting value of the
semaphore is?
(a) 1
(b) 3
(c) 2
(d) None
Q. A system uses FIFO policy for page CO6 d
No: replacement. It has 5 page frames
6 with no pages loaded to begin with.
The system first accesses 100 distinct
pages in some order and then access
the same 100 pages but now in the
reverse order. How many page faults
will occur?
(a) 180
(b) 190
(c) 200
(d) none
A system has 3 co-operating processes CO4 b
sharing a resource with 4 instances. If
each process needs maximum 2
instances, then deadlock will occur or
not?
(a) yes
(b) no
(c) can’t say
Suppose, s is a Semaphore with the CO3 c
initial value of 2. There are four active
processes A, B, C and D are executing
in the following order: A: P(s), B: P(s),
C: V(s), D: P(s), C: P(s). At the end
how many processes will be blocked?
(a) 0
(b) 2
(c) 1
(d) none
medium term scheduler taken place CO1 e
(a) between ready state and execution
state
(b) between start state and ready state
(c) between execution state and
termination state
(d) between execution state and
waiting state
(e) none of these
Q. CO1 c and d
No:
7

The operating system maintains a CO6 d


______ table that keeps track of how
many frames have been allocated, how
many are there, and how many are
available.
a) memory
b) mapping
c) page
d) frame
In real time operating system CO3 d
____________
a) process scheduling can be done
only once
b) all processes have the same priority
c) kernel is not required
d) a task must be serviced by its
deadline period
Program always deals with: CO6 a
A. logical address
B. absolute address
C. physical address
D. relative address

SECTION-B(Answer Any Three Questions. Each Question carries 12


Marks)

Time: 1 Hour and 30 Minutes (3×12=36 Marks)

Questio Question CO
n No Mappi
ng

Q.No:8 Consider the following snapshot of a system with 5 processes CO4,


(P1 … P5) and 4 resources (R1 … R4). Available resources R1: CO5,
2, R2: 1, R3: 1 and R4: 0 CO6,

Where, X = Roll no % 6
(a) Check that the aforementioned system can reach in safe
state or not? If it is in safe state, then what is the safe
sequence?
(b) If P4 requests (0 1 0 1) resources, then it can be granted or
not?

Ans: (a) 6 marks


(b) 6 marks
Consider the following snapshot of a system with 5 processes
(P1 … P5) and 4 resources (R1 … R4). Available resources R1:
2, R2: 1, R3: Y and R4: 0

Where, X = Roll no % 6
(a) For which value of Y, the aforementioned system can reach
in safe state? What is the safe sequence?
(b) If P4 requests (0 1 0 1) resources, then it can be granted or
not?

Ans: (6marks)
(b) (6 marks)
(a) A system is having ‘N’ user processes. Each requires 4 unit
of resource ‘R’. What is the minimum number of units of ‘R’
such that no deadlock occurs? N = right most significant digit
of your Roll No.( ex:- for Roll No. 180854, N=4) (5
marks)

Ans: (Sum of max needs of all N processes – N)+1


If N = 3, then ((3 X 4) - 3)+1 = 10

(b) Consider the following program segments for two different


processes executing concurrently:

Variable X starts at zero and is a shared variable. Variables A


and B are not shared variables. If Processes Pl and P2 execute
only once at any speed, what is the largest possible value of X?
Justify. (marks 4)

Ans: X=4

If Procedure P2 runs before P1

Then, X will be 1

Then it will be 2 and finally 4 after the two iterations of


Procedure P1

Marks to be awarded considering the approach and steps in


writing the solution
(c) Suppose, in a distributed environment, where multiple
computers or systems provide various services to the end
users. Therefore, tasks or jobs need to be distributed among
the systems such a way that the vast number of users gets
efficient services. In such scenario, the users may demand
various metrics like, low computation cost, less waiting time
and so on. Here, we are planning to use such existing CPU
scheduling algorithm which can provide high throughput
where, others metrics are less bother to us.
1st Explain why the selected existing CPU scheduling
algorithm is suitable for the aforementioned environment?
(marks 3)

Ans: Selected cpu scheduling algo will be SJF and SRTF. (need
explanation)
Q.No:9 Consider process arrival as given below where N = right most CO3,
significant digit of your Roll No.( ex:- for Roll No. 180854, CO4
N=4):

Process CPU Burst Arrival Time Priority


Time
A 10 0 3
B 17 5 2
C 5 9 N
D 2 N 1
E 9 7 6
Calculate the following for priority (preemptive) and round
robin (time quantum = 3 ms) CPU scheduling algorithm:

i. Average waiting time


ii. Turnaround time for each process
iii. Order of completion
(Note:-lower digits indicate higher priority)
(12 marks)

Ans:
Data to be finalized by finding the value of N for each Roll No
Preemptive Priority Scheduling(6 Marks)
Round Robin(6 Marks)

Mark distribution for each solution(Preemptive


Priority/ Round Robin)

Order of execution(Gantt Chart)(3 marks)

Waiting Time:(2marks)

Turn Around Time:(1 mark)

Marks to be awarded considering the approach and steps in


writing the solution

The arrival time and duration of the CPU and I/O bursts for
each of the three processes A, B, and C are given in the table
below. Each process has a CPU burst followed by an I/O burst
followed by another CPU burst. Assume that each process has
its own I/O resource.
Process Arrival CPU I/O burst CPU
time burst burst
P1 0 1 4 Roll no %
5
P2 2 3 3 1
P3 3 1 3 1

The multi programmed operating system uses the shortest


remaining time first (SRTF) scheduling. What are the
completion times of the processes A, B and C and find
individual waiting times of processes? (12 marks)

Solution:
Consider process arrival as given below where N = right most
significant digit of your Roll No.( ex:- for Roll No. 180854,
N=4):

Process CPU Burst Time Arrival Time Priority


A 10 0 4
B 15 5 7
C 2 9 N
D 8 N 1
E 6 7 6
Calculate the following for priority (preemptive) and round
robin (time quantum = 3 ms) CPU scheduling algorithm:

i. Average waiting time


ii. Turnaround time for each process
iii. Order of completion
(Note:-higher digits indicate higher priority) (12 marks)
Ans: Data to be finalized by finding the value of N for each
Roll No
Preemptive Priority Scheduling(6 Marks)
Round Robin(6 Marks)

Mark distribution for each solution(Preemptive


Priority/ Round Robin)

Order of execution(Gantt Chart)(3 marks)

Waiting Time:(2marks)

Turn Around Time:(1 mark)

Marks to be awarded considering the approach and steps in


writing the solution
Q.No:1 During this lockdown period, you are playing Ludo with your n CO4,
0 number of family members where, n < 5. Assume that all the CO2,
tokens are in the starting square and consider following CO5
scenarios: If the outcome of the dice is 6 (six), then you can
move your one token and get the chance to play dice again;
otherwise, you can move your one token and give the dice to
the next player.
Think of the players as processes which should be
synchronized. You are required to write a code for it using
semaphore. Your answer should first (i) list what
synchronization and/or what critical section problems you
have to solve, (ii) define what semaphore(s) you have to use
(including their initial value(s)), and (iii) then write the
pseudo code for it. You can assume that wait and signal are
variables as primitive calls on a semaphore with their usual
meanings. (12 marks)

Ans: i) a. if the outcome of the dice is 6, then all the other players must
wait.
b. if the outcome of the dice is other than 6, then immediate next player
gets access of the dice and other players must wait.
ii) Binary semaphore s for ensuring access of the dice and initial value is
1 i.e., available
Counting semaphores p[0] = 1, p[1]=p[2]=p[3]=0 ensure that which process
will get access of dice next.
iii)
while(true)
¿

Assume a set X of n processes, where n< 20 with process IDs


[0, n-1]. A function void Barrier(int pid) is defined over the set
X such that if any one process P0 in X with a process ID pid0
calls Barrier(int pid0), it is blocked until all processes in X
have called Barrier( ) with their process IDs. Write the pseudo
code for the Barrier( ) function using only semaphores, you
cannot use any shared variables; however, you can use any
number of semaphores.

First list the semaphores that you will use and their initial
values (don’t worry about who creates and initializes them).
Then show the code for Barrier( ) that uses the semaphores
declared by making P/Wait and V/Signal calls on them.(12
marks)

Solution:

struct barrier_type

// how many processors have entered the barrier

// initialize to 0

int arrive_counter;

// how many processors have exited the barrier

// initialize to p

int leave_counter;

int flag;

std::mutex lock;

};

// barrier for p processors

void barrier(barrier_type* b, int p)

b->lock.lock();

if (b->arrive_counter == 0)

b->lock.unlock();

while (b->leave_counter != p); // wait for all to leave before


clearing

b->lock.lock();
b->flag = 0; // first arriver clears flag

b->arrive_counter++;

if (b->arrive_counter == p) // last arriver sets flag

b->arrive_counter = 0;

b->leave_counter = 0;

b->flag = 1;

b->lock.unlock();

while (b->flag == 0); // wait for flag

b->lock.lock();

b->leave_counter++;

b->lock.unlock();

In a civilized society, a gentle man lives with his spouse and his
elderly parents. Due to old age, his parents cannot be left alone
in the house. So, at least any one of the spouse must be
available in the house. Write a synchronize solution using
semaphore for this problem. (12 marks)

Ans: enum {in,out,desire_out};


int spouse_state[2] = {out};
Semaphore spouse[2] = {0}, mutex=1;

spouse_work(i)
{
while(1)
{
enter_house(i);
takecare_parent();
leave_house(i);
}
}

enter_house(i)
{
p(mutex)
spouse_state[i]=in;
check_spouse_status((i+1)%2);
v(mutex)
}

check_spouse_status(i)
{
if(spouse_state[(i+1)%2] == in && spouse_state[i] ==
desire_out)
{
spouse_state[i] = out;
v(spouse[i])
}
}

leave_house(i)
{
p(mutex)
spouse_state[i] == desire_out;
check_spouse_status(i);
v(mutex)
p(spouse[i])
}
Q.No:11 (a) Why SJF and SRTF cannot be applied in real world CO3,
solution? What is the solution for that? – discuss briefly CO4,CO
(marks 3) 5, CO6

Ans: Have to know the execution time of the future upcoming


processes. (need explanation)
Soln: Static methods (process size, process type) and dynamic
methods (Averaging and exponential Avg.)

(b) Consider the following page reference strings: 7, 0, 1, 2, 0,


3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, X, 0, 1. What will be the
difference in page faults between optimal page replacement
and LRU with three empty frames? Note: X = roll no % 7
(marks 5)
Solution:
(c) A machine has 56-bit virtual addresses and 32-bit physical
addresses. The size of a page is 4K. Find the number of entries
needed for a conventional page table.(marks 4)

Ans: 4K pages = 12 bits of offset. 56 -12 = 44 bits are used for


page numbers. 2^44 PTEs are possible in a conventional page
table.
(a)

(6 marks)
Solution:
Consider Roll No. 20054263%8=7
The partitions are 4k,7k,20k,2k, now due to the best-fit algorithm,

1. Size of 2k job (P1) will fit in 2k partition and execute for 4 unit


2. Size of 14kjob (P2) will be fit in 20k partition and execute
for 10unit
3. Size of 3k job (P3) will be fit in 4k partition and execute for 2 unit
4. Size of 7k job (P7) will be fit in 7k partition now execute
for 8 unit. All partitions are full.

SO the p7 will be completed at 8 unitsof time assuming all processes in the


partitions are executed parallely.

Partitions Job distributed as per best fit


4k 3k(P3)
7k 7k(P7),6k(P4)
20k 14k(P2), 10K(P6), 6k(P5)
2k 2k(P1)

Segmentation

Segmentation is a memory management technique in which each job is


divided into several segments of different sizes, one for each module that
contains pieces that perform related functions. Each segment is actually a
different logical address space of the program.

When a process is to be executed, its corresponding segmentation are


loaded into non-contiguous memory though every segment is loaded into a
contiguous block of available memory.

Segmentation memory management works very similar to paging but here


segments are of variable-length where as in paging pages are of fixed size.

A program segment contains the program's main function, utility functions,


data structures, and so on. The operating system maintains a segment map
table for every process and a list of free memory blocks along with segment
numbers, their size and corresponding memory locations in main memory.
For each segment, the table stores the starting address of the segment and
the length of the segment. A reference to a memory location includes a
value that identifies a segment and an offset.
(b)
(i) A machine has 64-bit virtual addresses and 32-bit physical
addresses. The size of a page is 8K. Find the number of entries
needed for a conventional page table. (3 marks)

Ans: Size of a page is 8K. So, from the 64 bit VA, 13 bits are
going to be used for the offset. 64 – 13 = 51 bits can be used for
the page number. So, a conventional page table might contain
up to 2^51 PTEs.

(ii)A machine has 72-bit virtual addresses. Page size of 1GB,


and page table entry is 8B. Show the virtual address split w.r.t
page number and page offset. (3 marks)

Ans: 1 GB pages will need 30 bits of offset. 72 – 30 = 42 bits


can be used for page numbers. Split is 42:30 for page
number:offset.
(a) A machine has 64-bit virtual addresses. Page size of 16KB,
and page table entry is 4B. Show the virtual address split w.r.t
page number and page offset. (3 marks)

Ans: 16 KB pages = 14 bits of offset. 64 – 16 = 48 bits can be


used for page numbers. So, the split if 48:14 for page
number:offset.

(b) Explain static and dynamic linking with proper example.(3


marks)

Ans: Static linking is when function calls are patched at link


time right into the object file. Dynamic linking is when the OS
patches the location of a function at runtime. Example: In
Windows, if a piece of program is having to use dll files at
runtime then it is using dynamic linking. If it is not having to
use dll files and is still able to use external libraries then the
function code for those calls and baked into the object code
and that is static linking.

(c)
Where x = roll no % 9 (marks 6)

Solution:

Segmentation

In Operating Systems, Segmentation is a memory management technique


in which the memory is divided into the variable size parts. Each part is
known as a segment which can be allocated to a process.

Paging is more close to the Operating system rather than the User. It
divides all the processes into the form of pages regardless of the fact that a
process can have some relative parts of functions which need to be loaded
in the same page.

The details about each segment are stored in a table called a segment
table. Segment table is stored in one (or many) of the segments.
Segment table contains mainly two information about segment:

1. Base: It is the base address of the segment


2. Limit: It is the length of the segment.

You might also like