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

Find the size of the memory if its address consists of 22 bits.

Assume the memory is 2-


byte addressable.
Solution –
If the given address consists of ‘k’ bits, then 2 k locations are possible.
Size of memory = 2k x Size of one location.
According to the question, number of locations with 22 bits = 2 22 locations
Given that the size of the memory is 2-bytes addressable, which means that the size of one
location is 2 bytes.
Hence, the size of memory = 2 22 x 2 bytes = 223 bytes = 8 MB.

Calculate the number of address bits, if the memory has a size of 16 GB. Assume the
memory is 4-byte addressable.
Solution –
If the given address consists of ‘k’ bits, then 2 k locations are possible.
Size of memory = 2k x Size of one location.
Given that the size of memory is 16 GB. (16 GB = 2 34 B)
2k x 4 = 234
2k = 234 / 22 (∵ 22 = 4)
2k = 232
∴ k = 32 bits

Consider a machine with 32 bit logical addresses, 4 KB page size and page table
entries of 4 bytes each. Find the size of the page table in bytes. Assume the memory is
byte addressable.
Solution –
Given – No. of bits = 32 bits
Page Size = 4 KB = 4 x 2 10 bytes
Page table entry size = 4 bytes
Size of page table = Number of entries in page table x Page table entry size
Number of entries in page table = Process size / Page size
Process Size = Number of address bits
Thus, Process size = 2 32 bytes = 230 x 22 bytes = 4 GB
Number of entries in page table = 4 x 2 30 / 4 x 210 = 220 pages
Size of page table = 2 20 x 4 = 4 MB

Consider a system with page table entries of 8 bytes each. If the size of the page table
is 256 bytes, what is the number of entries in the page table?
Solution –
Size of page table = Number of entries in the page table x page table entry size
Given – Size of page table = 256 bytes, page table entry size = 8 bytes.
Thus, 256 = number of entries in page table x 8
Number of entries in the page table = 256 / 8 = 32 = 2 5

Find the total number of frames. If a system, size of the main memory is 2 30 bytes, the
page size is 4 KB and the size of each page table entry is 32-bit.
Solution –
Given – Size of main memory = 2 30 B, page size = 4 KB = 2 2 KB = 212 B (∵ 1 KB = 210 B)
Size of main memory = Total number of frames x page size.
230 = Total number of frames x 2 12
Total number of frames = 2 30 / 212 = 218

Consider a machine with 64 MB physical memory and a 32-bit virtual address space. If
the page size is 4KB, what is the approximate size of the page table? (GATE 2001)

(a) 16 MB
(b) 8 MB
(c) 2 MB
(d) 24 MB

Answer: (c)

Explanation:
A page entry is used to get address of physical memory. Here we assume that single level of
Paging is happening. So the resulting page table will contain entries for all the pages of the
Virtual address space.

Number of entries in page table =


(virtual address space size)/(page size)

Using above formula we can say that there will be 2^(32-12) = 2^20 entries in page table.

No. of bits required to address the 64MB Physical memory = 26.

So there will be 2^(26-12) = 2^14 page frames in the physical memory. And page table needs
to store the address of all these 2^14 page frames. Therefore, each page table entry will
contain 14 bits address of the page frame and 1 bit for valid-invalid bit.

Since memory is byte addressable. So we take that each page table entry is 16 bits i.e. 2 bytes
long.

Size of page table =


(total number of page table entries) *(size of a page table entry)
= (2^20 *2) = 2MB

Consider Peterson’s algorithm for mutual exclusion between two concurrent processes
i and j. The program executed by process is shown below.

repeat
flag [i] = true;
turn = j;
while ( P ) do no-op;
Enter critical section, perform actions, then exit critical
section
flag [ i ] = false;
Perform other non-critical section actions.
until false;
For the program to guarantee mutual exclusion, the predicate P in the while loop should
be (GATE 2001)

a) flag [j] = true and turn = i


b) flag [j] = true and turn = j
c) flag [i] = true and turn = j
d) flag [i] = true and turn = i

Answer: (b)

Basically, Peterson’s algorithm provides guaranteed mutual exclusion by using the two
following constructs – flag[] and turn. flag[] controls that the willingness of a process to be
entered in critical section. While turncontrols the process that is allowed to be entered in
critical section. So by replacing P with the following,

flag [j] = true and turn = j

process i will not enter critical section if process j wants to enter critical section and it is
process j’s turn to enter critical section. The same concept can be extended for more than two
processes. For details, refer the following.

Suppose the time to service a page fault is on the average 10 milliseconds, while a
memory access takes 1 microsecond. Then a 99.99% hit ratio results in average memory
access time of

(a) 1.9999 milliseconds


(b) 1 millisecond
(c) 9.999 microseconds
(d) 1.9999 microseconds

Answer: (d)

Explanation:

Average memory access time =


[(% of page miss)*(time to service a page fault) +
(% of page hit)*(memory access time)]/100

So, average memory access time in microseconds is.


(99.99*1 + 0.01*10*1000)/100 = (99.99+100)/1000 = 199.99/1000 =1.9999 µs

In a system with 32 bit virtual addresses and 1 KB page size, use of one-level page tables
for virtual to physical address translation is not practical because of (GATE CS 2003)

a) the large amount of internal fragmentation


b) the large amount of external fragmentation
c) the large memory overhead in maintaining page tables
d) the large computation overhead in the translation process

Answer (c)
Since page size is too small it will make size of page tables huge.

Size of page table =


(total number of page table entries) *(size of a page table entry)

Let us see how many entries are there in page table

Number of entries in page table =


(virtual address space size)/(page size)
= (2^32)/(2^10)
= 2^22

Now, let us see how big each entry is.


If size of physical memory is 512 MB then number of bits required to address a byte in 512
MB is 29. So, there will be (512MB)/(1KB) = (2^29)/(2^10) page frames in physical
memory. To address a page frame 19 bits are required. Therefore, each entry in page table is
required to have 19 bits.

Note that page table entry also holds auxiliary information about the page such
as a present bit, a dirty or modified bit, address space or process ID information,
amongst others. So size of page table
> (total number of page table entries) *(size of a page table entry)
> (2^22 *19) bytes
> 9.5 MB

A process executes the code

fork ();
fork ();
fork ();

The total number of child processes created is

(A) 3
(B) 4
(C) 7
(D) 8

Answer (C)

Let us put some label names for the three lines

fork (); // Line 1


fork (); // Line 2
fork (); // Line 3

L1 // There will be 1 child process created by line 1


/ \
L2 L2 // There will be 2 child processes created by line 2
/ \ / \
L3 L3 L3 L3 // There will be 4 child processes created by line 3

We can also use direct formula to get the number of child processes. With n fork statements,
there are always 2^n – 1 child processes. Also see this post for more details.

consider the 3 processes, P1, P2 and P3 shown in the table

Process Arrival time Time unit required


P1 0 5
P2 1 7
P3 3 4

The completion order of the 3 processes under the policies FCFS and RRS (round robin
scheduling with CPU quantum of 2 time units) are

(A) FCFS: P1, P2, P3 RR2: P1, P2, P3


(B) FCFS: P1, P3, P2 RR2: P1, P3, P2
(C) FCFS: P1, P2, P3 RR2: P1, P3, P2
(D) FCFS: P1, P3, P2 RR2: P1, P2, P3

Answer (C)

Consider the virtual page reference string

1, 2, 3, 2, 4, 1, 3, 2, 4, 1

On a demand paged virtual memory system running on a computer system that main
memory size of 3 pages frames which are initially empty. Let LRU, FIFO and
OPTIMAL denote the number of page faults under the corresponding page
replacements policy. Then

(A) OPTIMAL < LRU < FIFO


(B) OPTIMAL < FIFO < LRU
(C) OPTIMAL = LRU
(D) OPTIMAL = FIFO

Answer (B)

The OPTIMAL will be 5, FIFO 6 and LRU 9.

A file system with 300 GByte uses a file descriptor with 8 direct block address. 1
indirect block address and 1 doubly indirect block address. The size of each disk block
is 128 Bytes and the size of each disk block address is 8 Bytes. The maximum possible
file size in this file system is

(A) 3 Kbytes
(B) 35 Kbytes
(C) 280 Bytes
(D) Dependent on the size of the disk

Answer (B)

Total number of possible addresses stored in a disk block = 128/8 = 16


Maximum number of addressable bytes due to direct address block = 8*128
Maximum number of addressable bytes due to 1 single indirect address block = 16*128
Maximum number of addressable bytes due to 1 double indirect address block = 16*16*128
The maximum possible file size = 8*128 + 16*128 + 16*16*128 = 35KB

Let the page fault service time be 10ms in a computer with average memory access time
being 20ns. If one page fault is generated for every 10^6 memory accesses, what is the
effective access time for the memory?

(A) 21ns
(B) 30ns
(C) 23ns
(D) 35ns

Answer (B)

Let P be the page fault rate


Effective Memory Access Time = p * (page fault service time) +
(1 - p) * (Memory access time)
= ( 1/(10^6) )* 10 * (10^6) ns +
(1 - 1/(10^6)) * 20 ns
= 30 ns (approx)

Consider the following table of arrival time and burst time for three processes P0, P1
and P2.

Process Arrival time Burst Time


P0 0 ms 9 ms
P1 1 ms 4 ms
P2 2 ms 9 ms
The pre-emptive shortest job first scheduling algorithm is used. Scheduling is carried
out only at arrival or completion of processes. What is the average waiting time for the
three processes?
(A) 5.0 ms
(B) 4.33 ms
(C) 6.33 ms
(D) 7.33 ms

Answer: – (A)

Process P0 is allocated processor at 0 ms as there is no other process in ready queue. P0 is


preempted after 1 ms as P1 arrives at 1 ms and burst time for P1 is less than remaining time
of P0. P1 runs for 4ms. P2 arrived at 2 ms but P1 continued as burst time of P2 is longer than
P1. After P1 completes, P0 is scheduled again as the remaining time for P0 is less than the
burst time of P2.

P0 waits for 4 ms, P1 waits for 0 ms amd P2 waits for 11 ms. So average waiting time is
(0+4+11)/3 = 5.

A system uses FIFO policy for page replacement. It has 4 page frames with no pages
loaded to begin with. The system first accesses 100 distinct pages in some order and
then accesses the same 100 pages but now in the reverse order. How many page faults
will occur? (GATE CS 2010)

(A) 196
(B) 192
(C) 197
(D) 195

Answer (A)

Access to 100 pages will cause 100 page faults. When these pages are accessed in reverse
order, the first four accesses will node cause page fault. All other access to pages will cause
page faults. So total number of page faults will be 100 + 96.

Which of the following statements are true? (GATE CS 2010)


I. Shortest remaining time first scheduling may cause starvation
II. Preemptive scheduling may cause starvation
III. Round robin is better than FCFS in terms of response time
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III
Answer (D)
I) Shortest remaining time first scheduling is a preemptive version of shortest job scheduling.
It may cause starvation as shorter processes may keep coming and a long CPU burst process
never gets CPU.
II) Preemption may cause starvation. If priority based scheduling with preemption is used,
then a low priority process may never get CPU.
III) Round Robin Scheduling improves response time as all processes get CPU after a
specified time.

Consider the methods used by processes P1 and P2 for accessing their critical sections
whenever needed, as given below. The initial values of shared boolean variables S1 and
S2 are randomly assigned.

Method Used by P1
while (S1 == S2) ;
Critica1 Section
S1 = S2;
Method Used by P2
while (S1 != S2) ;
Critica1 Section
S2 = not (S1);

Which one of the following statements describes the properties achieved?

(A) Mutual exclusion but not progress


(B) Progress but not mutual exclusion
(C) Neither mutual exclusion nor progress
(D) Both mutual exclusion and progress

Answer (A)

It can be easily observed that the Mutual Exclusion requirement is satisfied by the above
solution, P1 can enter critical section only if S1 is not equal to S2, and P2 can enter critical
section only if S1 is equal to S2.

Progress Requirement is not satisfied. Let us first see definition of Progress Requirement.

Progress Requirement: If no process is executing in its critical section and there exist some
processes that wishes to enter their critical section, then the selection of the processes that
will enter the critical section next cannot be postponed indefinitely.
If P1 or P2 want to re-enter the critical section, then they cannot even if there is other process
running in critical section.

In which one of the following page replacement policies, Belady’s anomaly may occur?

(A) FIFO
(B) Optimal
(C) LRU
(D) MRU

Answer (A)

Belady’s anomaly proves that it is possible to have more page faults when increasing the
number of page frames while using the First in First Out (FIFO) page replacement algorithm.

33) The essential content(s) in each entry of a page table is / are

(A) Virtual page number


(B) Page frame number
(C) Both virtual page number and page frame number
(D) Access right information

Answer (B)
A page table entry must contain Page frame number. Virtual page number is typically used as
index in page table to get the corresponding page frame number.

Consider a system with 4 types of resources R1 (3 units), R2 (2 units), R3 (3 units), R4 (2


units). A non-preemptive resource allocation policy is used. At any given instance, a
request is not entertained if it cannot be completely satisfied. Three processes P1, P2, P3
request the sources as follows if executed independently.

Process P1:
t=0: requests 2 units of R2
t=1: requests 1 unit of R3
t=3: requests 2 units of R1
t=5: releases 1 unit of R2
and 1 unit of R1.
t=7: releases 1 unit of R3
t=8: requests 2 units of R4
t=10: Finishes

Process P2:
t=0: requests 2 units of R3
t=2: requests 1 unit of R4
t=4: requests 1 unit of R1
t=6: releases 1 unit of R3
t=8: Finishes

Process P3:
t=0: requests 1 unit of R4
t=2: requests 2 units of R1
t=5: releases 2 units of R1
t=7: requests 1 unit of R2
t=8: requests 1 unit of R3
t=9: Finishes

Which one of the following statements is TRUE if all three processes run concurrently
starting at time t=0?

(A) All processes will finish without any deadlock


(B) Only P1 and P2 will be in deadlock.
(C) Only P1 and P3 will be in a deadlock.
(D) All three processes will be in deadlock

Answer (A)

We can apply the following Deadlock Detection algorithm and see that there is no process
waiting indefinitely for a resource.

Consider a disk system with 100 cylinders. The requests to access the cylinders occur in
following sequence:
4, 34, 10, 7, 19, 73, 2, 15, 6, 20

Assuming that the head is currently at cylinder 50, what is the time taken to satisfy all
requests if it takes 1ms to move from one cylinder to adjacent one and shortest seek
time first policy is used?

(A) 95ms
(B) 119ms
(C) 233ms
(D) 276ms

Answer (B)

4, 34, 10, 7, 19, 73, 2, 15, 6, 20

Since shortest seek time first policy is used, head will first move to 34. This move will cause
16*1 ms. After 34, head will move to 20 which will cause 14*1 ms. And so on. So cylinders
are accessed in following order 34, 20, 19, 15, 10, 7, 6, 4, 2, 73 and total time will be (16 +
14 + 1 + 4 + 5 + 3 + 1 + 2 + 2 + 71)*1 = 119 ms.

In the following process state transition diagram for a uniprocessor system, assume
that there are always some processes in the ready state: Now consider the following
statements:

I. If a process makes a transition D, it would result in another process making transition


A immediately.
II. A process P2 in blocked state can make transition E while another process P1 is in
running state.
III. The OS uses preemptive scheduling.
IV. The OS uses non-preemptive scheduling.
Which of the above statements are TRUE?
(A) I and II
(B) I and III
(C) II and III
(D) II and IV

Answer (C)

I is false. If a process makes a transition D, it would result in another process making


transition B, not A.
II is true. A process can move to ready state when I/O completes irrespective of other process
being in running state or not.
III is true because there is a transition from running to ready state.
IV is false as the OS uses preemptive scheduling.

The enter_CS() and leave_CS() functions to implement critical section of a process are
realized using test-and-set instruction as follows:

void enter_CS(X)
{
while test-and-set(X) ;
}
void leave_CS(X)
{
X = 0;
}
In the above solution, X is a memory location associated with the CS and is initialized to
0. Now consider the following statements:
I. The above solution to CS problem is deadlock-free
II. The solution is starvation free.
III. The processes enter CS in FIFO order.
IV. More than one process can enter CS at the same time.
Which of the above statements is TRUE?
(A) I only
(B) I and II
(C) II and III
(D) IV only

Answer (A)

The above solution is a simple test-and-set solution that makes sure that deadlock doesn’t
occur, but it doesn’t use any queue to avoid starvation or to have FIFO order.

A multilevel page table is preferred in comparison to a single level page table for
translating virtual address to physical address because

(A) It reduces the memory access time to read or write a memory location.
(B) It helps to reduce the size of page table needed to implement the virtual address
space of a process.
(C) It is required by the translation lookaside buffer.
(D) It helps to reduce the number of page faults in page replacement algorithms.

Answer (B)

The size of page table may become too big (See this) to fit in contiguous space. That is why
page tables are typically divided in levels.

The data blocks of a very large file in the Unix file system are allocated using

(A) contiguous allocation


(B) linked allocation
(C) indexed allocation
(D) an extension of indexed allocation

Answer (D)

The Unix file system uses an extension of indexed allocation. It uses direct blocks, single
indirect blocks, double indirect blocks and triple indirect blocks.
The P and V operations on counting semaphores, where s is a counting semaphore, are
defined as follows:

P(s) : s = s - 1;
if (s < 0) then wait;
V(s) : s = s + 1;
if (s <= 0) then wakeup a process waiting on s;

Assume that Pb and Vb the wait and signal operations on binary semaphores are
provided. Two binary semaphores Xb and Yb are used to implement the semaphore
operations P(s) and V(s) as follows:

P(s) : Pb(Xb);
s = s - 1;
if (s < 0) {
Vb(Xb) ;
Pb(Yb) ;
}
else Vb(Xb);

V(s) : Pb(Xb) ;
s = s + 1;
if (s <= 0) Vb(Yb) ;
Vb(Xb) ;

The initial values of Xb and Yb are respectively

(A) 0 and 0
(B) 0 and 1
(C) 1 and 0
(D) 1 and 1

Answer (C)

Both P(s) and V(s) operations are perform Pb(xb) as first step. If Xb is 0, then all processes
executing these operations will be blocked. Therefore, Xb must be 1.

If Yb is 1, it may become possible that two processes can execute P(s) one after other
(implying 2 processes in critical section). Consider the case when s = 1, y = 1. So Yb must be
0.

Which of the following statements about synchronous and asynchronous I/O is NOT
true?

(A) An ISR is invoked on completion of I/O in synchronous I/O but not in asynchronous I/O
(B) In both synchronous and asynchronous I/O, an ISR (Interrupt Service Routine) is invoked
after completion of the I/O
(C) A process making a synchronous I/O call waits until I/O is complete, but a process
making an asynchronous I/O call does not wait for completion of the I/O
(D) In the case of synchronous I/O, the process waiting for the completion of I/O is woken up
by the ISR that is invoked after the completion of I/O

Answer (A)

In both Synchronous and Asynchronous, an interrupt is generated on completion of I/O. In


Synchronous, interrupt is generated to wake up the process waiting for I/O. In Asynchronous,
interrupt is generated to inform the process that the I/O is complete and it can process the
data from the I/O operation.

A process executes the following code

for (i = 0; i < n; i++) fork();


The total number of child processes created is
(A) n
(B) 2^n – 1
(C) 2^n
(D) 2^(n+1) – 1;

Answer (B)

F0 // There will be 1 child process created by first fork


/ \
F1 F1 // There will be 2 child processes created by second fork
/ \ / \
F2 F2 F2 F2 // There will be 4 child processes created by third fork
/\ /\/\ /\
............... // and so on

If we sum all levels of above tree for i = 0 to n-1, we get 2^n – 1. So there will be 2^n – 1
child processes.

Which of the following is NOT true of deadlock prevention and deadlock avoidance
schemes?

(A) In deadlock prevention, the request for resources is always granted if the resulting state is
safe
(B) In deadlock avoidance, the request for resources is always granted if the result state is
safe
(C) Deadlock avoidance is less restrictive than deadlock prevention
(D) Deadlock avoidance requires knowledge of resource requirements a priori

Answer (A)

Deadlock prevention scheme handles deadlock by making sure that one of the four necessary
conditions don’t occur. In deadlock prevention, the request for a resource may not be granted
even if the resulting state is safe.

A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page
frame size of 4 Kbytes. Each page table entry is of size 4 bytes. A three level page table
is used for virtual to physical address translation, where the virtual address is used as
follows
• Bits 30-31 are used to index into the first level page table

• Bits 21-29 are used to index into the second level page table
• Bits 12-20 are used to index into the third level page table, and
• Bits 0-11 are used as offset within the page
The number of bits required for addressing the next level page table (or page frame) in
the page table entry of the first, second and third level page tables are respectively\
(A) 20, 20 and 20
(B) 24, 24 and 24
(C) 24, 24 and 20
(D) 25, 25 and 24

Answer (D)

Virtual address size = 32 bits


Physical address size = 36 bits
Physical memory size = 2^36 bytes
Page frame size = 4K bytes = 2^12 bytes
No. of bits required to access physical memory frame = 36 – 12 = 24
So in third level of page table, 24 bits are required to access an entry.
9 bits of virtual address are used to access second level page table entry and size of pages in
second level is 4 bytes. So size of second level page table is (2^9)*4 = 2^11 bytes. It means
there are (2^36)/(2^11) possible locations to store this page table. Therefore the second page
table requires 25 bits to address it. Similarly, the third page table needs 25 bits to address it.

Consider a disk pack with 16 surfaces, 128 tracks per surface and 256 sectors per track.
512 bytes of data are stored in a bit serial manner in a sector. The capacity of the disk
pack and the number of bits required to specify a particular sector in the disk are
respectively:
(A) 256 Mbyte, 19 bits
(B) 256 Mbyte, 28 bits
(C) 512 Mbyte, 20 bits
(D) 64 Gbyte, 28 bits

Answer (A)

Capacity of the disk = 16 surfaces X 128 tracks X 256 sectors X 512 bytes = 256 Mbytes.
To calculate number of bits required to access a sector, we need to know total number of
sectors. Total number of sectors = 16 surfaces X 128 tracks X 256 sectors = 2^19
So the number of bits required to access a sector is 19.

Group 1 contains some CPU scheduling algorithms and Group 2 contains some
applications. Match entries in Group 1 to entries in Group 2.

Group I Group II
(P) Gang Scheduling (1) Guaranteed Scheduling
(Q) Rate Monotonic Scheduling (2) Real-time Scheduling
(R) Fair Share Scheduling (3) Thread Scheduling
(A) P – 3 Q – 2 R – 1
(B) P – 1 Q – 2 R – 3
(C) P – 2 Q – 3 R – 1
(D) P – 1 Q – 3 R – 2

Answer (A)

Gang scheduling for parallel systems that schedules related threads or processes to run
simultaneously on different processors.

Rate monotonic scheduling is used in real-time operating systems with a static-priority


scheduling class. The static priorities are assigned on the basis of the cycle duration of the
job: the shorter the cycle duration is, the higher is the job’s priority.

Fair Share Scheduling is a scheduling strategy in which the CPU usage is equally distributed
among system users or groups, as opposed to equal distribution among processes. It is also
known as Guaranteed scheduling.

An operating system uses Shortest Remaining Time first (SRT) process scheduling
algorithm. Consider the arrival times and execution times for the following processes:

Process Execution time Arrival time


P1 20 0
P2 25 15
P3 10 30
P4 15 45
What is the total waiting time for process P2?
(A) 5
(B) 15
(C) 40
(D) 55

Answer (B)

A virtual memory system uses First In First Out (FIFO) page replacement policy and
allocates a fixed number of frames to a process. Consider the following statements:

P: Increasing the number of page frames allocated to a process sometimes increases the
page fault rate.

Q: Some programs do not exhibit locality of reference. Which one of the following is
TRUE?
(A) Both P and Q are true, and Q is the reason for P
(B) Both P and Q are true, but Q is not the reason for P.
(C) P is false, but Q is true
(D) Both P and Q are false.

Answer (B)
P is true. Increasing the number of page frames allocated to process may increases the no. of
page faults.

Q is also true, but Q is not the reason for-P as Belady’s Anomaly occurs for some specific
patterns of page references.

A single processor system has three resource types X, Y and Z, which are shared by
three processes. There are 5 units of each resource type. Consider the following
scenario, where the column alloc denotes the number of units of each resource type
allocated to each process, and the column request denotes the number of units of each
resource type requested by a process in order to complete execution. Which of these
processes will finish LAST?

alloc request X Y Z X Y Z P0 1 2 1 1 0 3 P1 2 0 1 0 1 2 P2 2 2 1 1 2 0
(A) P0
(B) P1
(C) P2
(D) None of the above, since the system is in a deadlock
Answer (C)

Once all resources (5, 4 and 3 instances of X, Y and Z respectively) are allocated, 0, 1 and 2
instances of X, Y and Z are left. Only needs of P1 can be satisfied. So P1 can finish its
execution first. Once P1 is done, it releases 2, 1 and 3 units of X, Y and Z respectively.
Among P0 and P2, needs of P0 can only be satisfied. So P0 finishes its execution. Finally, P2
finishes its execution.

Consider the following statements about user level threads and kernel level threads.
Which one of the following statement is FALSE?

(A) Context switch time is longer for kernel level threads than for user level threads.
(B) User level threads do not need any hardware support.
(C) Related kernel level threads can be scheduled on different processors in a multi-
processor system.
(D) Blocking one kernel level thread blocks all related threads.

Answer (D)

Since kernel level threads are managed by kernel, blocking one thread doesn’t cause all
related threads to block. It’s a problem with user level threads.

Consider three CPU-intensive processes, which require 10, 20 and 30 time units and
arrive at times 0, 2 and 6, respectively. How many context switches are needed if the
operating system implements a shortest remaining time first scheduling algorithm? Do
not count the context switches at time zero and at the end.
(A) 1
(B) 2
(C) 3
(D) 4

Answer (B)
Let three process be P0, P1 and P2 with arrival times 0, 2 and 6 respectively and CPU burst
times 10, 20 and 30 respectively. At time 0, P0 is the only available process so it runs. At
time 2, P1 arrives, but P0 has the shortest remaining time, so it continues. At time 6, P2
arrives, but P0 has the shortest remaining time, so it continues. At time 10, P1 is scheduled as
it is the shortest remaining time process. At time 30, P2 is scheduled. Only two context
switches are needed. P0 to P1 and P1 to P2.

A computer system supports 32-bit virtual addresses as well as 32-bit physical


addresses. Since the virtual address space is of the same size as the physical address
space, the operating system designers decide to get rid of the virtual memory entirely.
Which one of the following is true?
(A) Efficient implementation of multi-user support is no longer possible
(B) The processor cache organization can be made more efficient now
(C) Hardware support for memory management is no longer needed
(D) CPU scheduling can be made more efficient now

Answer (C)

For supporting virtual memory, special hardware support is needed from Memory
Management Unit. Since operating system designers decide to get rid of the virtual memory
entirely, hardware support for memory management is no longer needed

A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a
translation look-aside buffer (TLB) which can hold a total of 128 page table entries and
is 4-way set associative. The minimum size of the TLB tag is:
(A) 11 bits
(B) 13 bits
(C) 15 bits
(D) 20 bits
Answer (C)
Size of a page = 4KB = 2^12
Total number of bits needed to address a page frame = 32 – 12 = 20
If there are ‘n’ cache lines in a set, the cache placement is called n-way set associative. Since
TLB is 4 way set associative and can hold total 128 (2^7) page table entries, number of sets
in cache = 2^7/4 = 2^5. So 5 bits are needed to address a set, and 15 (20 – 5) bits are needed
for tag.

Consider three processes (process id 0, 1, 2 respectively) with compute time bursts 2, 4


and 8 time units. All processes arrive at time zero. Consider the longest remaining time
first (LRTF) scheduling algorithm. In LRTF ties are broken by giving priority to the
process with the lowest process id. The average turn around time is:
(A) 13 units
(B) 14 units
(C) 15 units
(D) 16 units

Answer (A)

Let the processes be p0, p1 and p2. These processes will be executed in following order.
p2 p1 p2 p1 p2 p0 p1 p2 p0 p1 p2
0 4 5 6 7 8 9 10 11 12 13 14
Turn around time of a process is total time between submission of the process and its
completion.
Turn around time of p0 = 12 (12-0)
Turn around time of p1 = 13 (13-0)
Turn around time of p2 = 14 (14-0)
Average turn around time is (12+13+14)/3 = 13.

Consider three processes, all arriving at time zero, with total execution time of 10, 20
and 30 units, respectively. Each process spends the first 20% of execution time doing
I/O, the next 70% of time doing computation, and the last 10% of time doing I/O again.
The operating system uses a shortest remaining compute time first scheduling algorithm
and schedules a new process either when the running process gets blocked on I/O or
when the running process finishes its compute burst. Assume that all I/O operations can
be overlapped as much as possible. For what percentage of time does the CPU remain
idle?
(A) 0%
(B) 10.6%
(C) 30.0%
(D) 89.4%

Answer (B)

Let three processes be p0, p1 and p2. Their execution time is 10, 20 and 30 respectively. p0
spends first 2 time units in I/O, 7 units of CPU time and finally 1 unit in I/O. p1 spends first 4
units in I/O, 14 units of CPU time and finally 2 units in I/O. p2 spends first 6 units in I/O, 21
units of CPU time and finally 3 units in I/O.

idle p0 p1 p2 idle
0 2 9 23 44 47

Total time spent = 47


Idle time = 2 + 3 = 5
Percentage of idle time = (5/47)*100 = 10.6 %

The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1


and fetches the old value of x in y without allowing any intervening access to the
memory location x. consider the following implementation of P and V functions on a
binary semaphore .

void P (binary_semaphore *s) {


unsigned y;
unsigned *x = &(s->value);
do {
fetch-and-set x, y;
} while (y);
}

void V (binary_semaphore *s) {


S->value = 0;
}
Which one of the following is true?
(A) The implementation may not work if context switching is disabled in P.
(B) Instead of using fetch-and-set, a pair of normal load/store can be used
(C) The implementation of V is wrong
(D) The code does not implement a binary semaphore

Answer (A)

Let us talk about the operation P(). It stores the value of s in x, then it fetches the old value of
x, stores it in y and sets x as 1. The while loop of a process will continue forever if some
other process doesn’t execute V() and sets the value of s as 0. If context switching is disabled
in P, the while loop will run forever as no other process will be able to execute V().

Consider the following snapshot of a system running n processes. Process i is holding Xi


instances of a resource R, 1 <= i <= n. currently, all instances of R are occupied.
Further, for all i, process i has placed a request for an additional Yi instances while
holding the Xi instances it already has. There are exactly two processes p and q such
that Yp = Yq = 0. Which one of the following can serve as a necessary condition to
guarantee that the system is not approaching a deadlock?
(A) min (Xp, Xq) < max (Yk) where k != p and k != q
(B) Xp + Xq >= min (Yk) where k != p and k != q
(C) max (Xp, Xq) > 1
(D) min (Xp, Xq) > 1

Answer (B)

Since both p and q don’t need additional resources, they both can finish and release Xp + Xq
resources without asking for any additional resource. If the resources released by p and q are
sufficient for another process waiting for Yk resources, then system is not approaching
deadlock.

What is the swap space in the disk used for?


(a) Saving temporary html pages
(b) Saving process data
(c) Storing the super-block
(d) Storing device drivers

Answer (b)

Swap space is typically used to store process data.

Increasing the RAM of a computer typically improves performance because:


(a) Virtual memory increases
(b) Larger RAMs are faster
(c) Fewer page faults occur
(d) Fewer segmentation faults occur

Answer (c)
Suppose n processes, P1, …. Pn share m identical resource units, which can be reserved
and released one at a time. The maximum resource requirement of process Pi is Si,
where Si > 0. Which one of the following is a sufficient condition for ensuring that
deadlock does not occur?

Answer (c)

In the extreme condition, all processes acquire Si-1 resources and need 1 more resource. So
following condition must be true to make sure that deadlock never occurs.

<m

The above expression can be written as following.

< (m + n)

A system is having 3 user processes each requiring 2 units of resource R. The minimum
number of units of R such that no deadlock will occur-

1. 3
2. 5
3. 4
4. 6

Solution-

In worst case,
The number of units that each process holds = One less than its maximum demand
So,
 Process P1 holds 1 unit of resource R
 Process P2 holds 1 unit of resource R
 Process P3 holds 1 unit of resource R

Thus,
 Maximum number of units of resource R that ensures deadlock = 1 + 1 + 1 = 3
 Minimum number of units of resource R that ensures no deadlock = 3 + 1 = 4

A system is having 10 user processes each requiring 3 units of resource R. The


minimum number of units of R such that no deadlock will occur _____?

Solution-

In worst case,
The number of units that each process holds = One less than its maximum demand
So,
 Process P1 holds 2 units of resource R
 Process P2 holds 2 units of resource R
 Process P3 holds 2 units of resource R and so on.
 Process P10 holds 2 units of resource R

Thus,
 Maximum number of units of resource R that ensures deadlock = 10 x 2 = 20
 Minimum number of units of resource R that ensures no deadlock = 20 + 1 = 21

A system is having 3 user processes P1, P2 and P3 where P1 requires 21 units of


resource R, P2 requires 31 units of resource R, P3 requires 41 units of resource R. The
minimum number of units of R that ensures no deadlock is _____?

Solution-

In worst case,
The number of units that each process holds = One less than its maximum demand
So,
 Process P1 holds 20 units of resource R
 Process P2 holds 30 units of resource R
 Process P3 holds 40 units of resource R

Thus,
 Maximum number of units of resource R that ensures deadlock = 20 + 30 + 40 = 90
 Minimum number of units of resource R that ensures no deadlock = 90 + 1 = 91

If there are 6 units of resource R in the system and each process in the system requires
3 units of resource R, then how many processes can be present at maximum so that no
deadlock will occur?

Solution-

In worst case,
The number of units that each process holds = One less than its maximum demand
So,
 Process P1 holds 2 units of resource R
 Process P2 holds 2 units of resource R
 Process P3 holds 2 units of resource R

Thus,
 Minimumnumber of processes that ensures deadlock = 3
 Maximum number of processes that ensures no deadlock = 3 – 1 = 2
Consider a system having m resources of the same type. These resources are shared by 3
processes A, B and C which have peak demands of 3, 4 and 6 respectively. For what
value of m, deadlock will not occur?
1. 7
2. 9
3. 10
4. 13

Solution-

In worst case,
The number of units that each process holds = One less than its maximum demand
So,
 Process A holds 2 units of resource R
 Process B holds 3 units of resource R
 Process C holds 5 units of resource R

Thus,
 Maximum number of units of resource R that ensures deadlock = 2 + 3 + 5 = 10
 Minimum number of units of resource R that ensures no deadlock = 10 + 1 = 11

So, any number of units greater than 11 will ensure no deadlock.


Thus, Option (D) is correct.

Consider a system having m resources of the same type being shared by n processes.
Resources can be requested and released by processes only one at a time. The system is
deadlock free if and only if-
1. The sum of all max needs is < m+n
2. The sum of all max needs is > m+n
3. Both of above
4. None of these

Solution-

We have derived above-


Maximum number of units of resource R that ensures deadlock = (∑xi – n)

Thus, For no deadlock occurrence,


Number of units of resource R must be > (∑xi – n)
i.e. m > (∑xi – n)
or ∑xi < m + n
Thus, Correct Option is (A).
Que: Consider the set of 4 processes whose arrival time and burst time are given below-

Burst Time
Process No. Arrival Time
CPU Burst I/O Burst CPU Burst

P1 0 3 2 2

P2 0 2 4 1

P3 2 1 3 2

P4 5 2 2 1

If the CPU scheduling policy is Shortest Remaining Time First, calculate the average waiting
time and average turn around time.

Solution-

Gantt Chart-

Now, we know-
 Turn Around time = Exit time – Arrival time
 Waiting time = Turn Around time – Burst time

Process Id Exit time Turn Around time Waiting time

P1 11 11 – 0 = 11 11 – (3+2) = 6

P2 7 7–0=7 7 – (2+1) = 4
P3 9 9–2=7 7 – (1+2) = 4

P4 16 16 – 5 = 11 11 – (2+1) = 8

Now,
 Average Turn Around time = (11 + 7 + 7 + 11) / 4 = 36 / 4 = 9 units
 Average waiting time = (6 + 4 + 4 + 8) / 4 = 22 / 5 = 4.4 units

Problem-01:

A single processor system has three resource types X, Y and Z, which are shared by three
processes. There are 5 units of each resource type. Consider the following scenario, where the
column alloc denotes the number of units of each resource type allocated to each process, and
the column request denotes the number of units of each resource type requested by a process
in order to complete execution. Which of these processes will finish LAST?
1. P0
2. P1
3. P2
4. None of the above since the system is in a deadlock

Alloc Request

X Y Z X Y Z

P0 1 2 1 1 0 3

P1 2 0 1 0 1 2

P2 2 2 1 1 2 0

Solution-

According to question-
 Total = [ X Y Z ] = [ 5 5 5 ]
 Total _Alloc = [ X Y Z ] = [5 4 3]

Now,
Available

= Total – Total_Alloc
= [ 5 5 5 ] – [5 4 3]
=[012]
Step-01:

 With the instances available currently, only the requirement of the process P1 can be
satisfied.
 So, process P1 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then,
Available
= [ 0 1 2 ] + [ 2 0 1]
=[213]

Step-02:

 With the instances available currently, only the requirement of the process P0 can be
satisfied.
 So, process P0 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[213]+[121]

=[334]

Step-03:

 With the instances available currently, the requirement of the process P2 can be satisfied.
 So, process P2 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[334]+[221]
=[555]

Thus,
 There exists a safe sequence P1, P0, P2 in which all the processes can be executed.
 So, the system is in a safe state.
 Process P2 will be executed at last.

Thus, Option (C) is correct.

Problem-02:

An operating system uses the banker’s algorithm for deadlock avoidance when managing the
allocation of three resource types X, Y and Z to three processes P0, P1 and P2. The table
given below presents the current system state. Here, the Allocation matrix shows the current
number of resources of each type allocated to each process and the Max matrix shows the
maximum number of resources of each type required by each process during its execution.

Allocation Max

X Y Z X Y Z

P0 0 0 1 8 4 3

P1 3 2 0 6 2 0

P2 2 1 1 3 3 3

There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system
is currently in safe state. Consider the following independent requests for additional resources
in the current state-

REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z


REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z

Which of the following is TRUE?


1. Only REQ1 can be permitted
2. Only REQ2 can be permitted
3. Both REQ1 and REQ2 can be permitted
4. Neither REQ1 nor REQ2 can be permitted

Solution-

According to question,
Available = [ X Y Z ] = [ 3 2 2 ]
Now,
Need = Max – Allocation
So, we have-

Allocation Max Need

X Y Z X Y Z X Y Z

P0 0 0 1 8 4 3 8 4 2

P1 3 2 0 6 2 0 3 0 0

P2 2 1 1 3 3 3 1 2 2
Currently, the system is in safe state.
(It is given in question. If we want, we can check)

Checking Whether REQ1 Can Be Entertained-

 Need of P0 = [ 0 0 2 ]
 Available = [ 3 2 2 ]

Clearly,
 With the instances available currently, the requirement of REQ1 can be satisfied.
 So, banker’s algorithm assumes that the request REQ1 is entertained.
 It then modifies its data structures as-

Allocation Max Need

X Y Z X Y Z X Y Z

P0 0 0 3 8 4 3 8 4 0

P1 3 2 0 6 2 0 3 0 0

P2 2 1 1 3 3 3 1 2 2

Available
=[322]–[002]
=[320]

 Now, it follows the safety algorithm to check whether this resulting state is a safe state or not.
 If it is a safe state, then REQ1 can be permitted otherwise not.

Step-01:

 With the instances available currently, only the requirement of the process P1 can be
satisfied.
 So, process P1 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[320]+[320]
=[640]

Now,
 It is not possible to entertain any process.
 The system has entered the deadlock state which is an unsafe state.
 Thus, REQ1 will not be permitted.
Checking Whether REQ2 Can Be Entertained-

 Need of P1 = [ 2 0 0 ]
 Available = [ 3 2 2 ]

Clearly,
 With the instances available currently, the requirement of REQ1 can be satisfied.
 So, banker’s algorithm assumes the request REQ2 is entertained.
 It then modifies its data structures as-

Allocation Max Need

X Y Z X Y Z X Y Z

P0 0 0 1 8 4 3 8 4 2

P1 5 2 0 6 2 0 1 0 0

P2 2 1 1 3 3 3 1 2 2

Available
=[322]–[200]
=[122]
 Now, it follows the safety algorithm to check whether this resulting state is a safe state or not.
 If it is a safe state, then REQ2 can be permitted otherwise not.

Step-01:

 With the instances available currently, only the requirement of the process P1 can be
satisfied.
 So, process P1 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[122]+[520]
=[642]

Step-02:

 With the instances available currently, only the requirement of the process P2 can be
satisfied.
 So, process P2 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[642]+[211]
=[853]

Step-03:

 With the instances available currently, the requirement of the process P0 can be satisfied.
 So, process P0 is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[853]+[001]
=[854]

Thus,
 There exists a safe sequence P1, P2, P0 in which all the processes can be executed.
 So, the system is in a safe state.
 Thus, REQ2 can be permitted.

Thus, Correct Option is (B).

Problem-03:

A system has 4 processes and 5 allocatable resource. The current allocation and
maximum needs are as follows-

Allocated Maximum

A 1 0 2 1 1 1 1 2 1 3

B 2 0 1 1 0 2 2 2 1 0

C 1 1 0 1 1 2 1 3 1 1

D 1 1 1 1 0 1 1 2 2 0

If Available = [ 0 0 X 1 1 ], what is the smallest value of x for which this is a safe state?

Solution-

Let us calculate the additional instances of each resource type needed by each process.
We know,
Need = Maximum – Allocation

So, we have-
Need

A 0 1 0 0 2

B 0 2 1 0 0

C 1 0 3 0 0

D 0 0 1 1 0

Case-01: For X = 0

If X = 0, then-
Available
=[00011]

 With the instances available currently, the requirement of any process can not be satisfied.
 So, for X = 0, system remains in a deadlock which is an unsafe state.

Case-02: For X = 1

If X = 1, then-
Available
=[00111]

Step-01:

 With the instances available currently, only the requirement of the process D can be satisfied.
 So, process D is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[00111]+[11110]
=[11221]

 With the instances available currently, the requirement of any process can not be satisfied.
 So, for X = 1, system remains in a deadlock which is an unsafe state.

Case-02: For X = 2

If X = 2, then-
Available
=[00211]

Step-01:

 With the instances available currently, only the requirement of the process D can be satisfied.
 So, process D is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[00211]+[11110]
=[11321]

Step-02:

 With the instances available currently, only the requirement of the process C can be satisfied.
 So, process C is allocated the requested resources.
 It completes its execution and then free up the instances of resources held by it.

Then-
Available
=[11321]+[11011]
=[22332]

Step-03:

 With the instances available currently, the requirement of both the processes A and B can be
satisfied.
 So, processes A and B are allocated the requested resources one by one.
 They complete their execution and then free up the instances of resources held by it.

Then-
Available
=[22332]+[10211]+[20110]
=[52653]

Thus,
 There exists a safe sequence in which all the processes can be executed.
 So, the system is in a safe state.
 Thus, minimum value of X that ensures system is in safe state = 2.

Consider six memory partitions of size 200 KB, 400 KB, 600 KB, 500 KB, 300 KB and
250 KB. These partitions need to be allocated to four processes of sizes 357 KB, 210 KB,
468 KB and 491 KB in that order.
Perform the allocation of processes using-
1. First Fit Algorithm
2. Best Fit Algorithm
3. Worst Fit Algorithm

Solution-

According to question,
The main memory has been divided into fixed size partitions as-

Let us say the given processes are-


 Process P1 = 357 KB
 Process P2 = 210 KB
 Process P3 = 468 KB
 Process P4 = 491 KB

Allocation Using First Fit Algorithm-

In First Fit Algorithm,


 Algorithm starts scanning the partitions serially.
 When a partition big enough to store the process is found, it allocates that partition to the
process.

The allocation of partitions to the given processes is shown below-

Step-01:

Step-02:

Step-03:
Step-04:

 Process P4 can not be allocated the memory.


 This is because no partition of size greater than or equal to the size of process P4 is available.

Allocation Using Best Fit Algorithm-

In Best Fit Algorithm,


 Algorithm first scans all the partitions.
 It then allocates the partition of smallest size that can store the process.

The allocation of partitions to the given processes is shown below-

Step-01:

Step-02:

Step-03:

Step-04:
Allocation Using Worst Fit Algorithm-

In Worst Fit Algorithm,


 Algorithm first scans all the partitions.
 It then allocates the partition of largest size to the process.

The allocation of partitions to the given processes is shown below-

Step-01:

Step-02:

Step-03:

 Process P3 and Process P4 can not be allocated the memory.


 This is because no partition of size greater than or equal to the size of process P3 and process
P4 is available.

Problem-02:

Consider the following heap (figure) in which blank regions are not in use and hatched
regions are in use-

The sequence of requests for blocks of size 300, 25, 125, 50 can be satisfied if we use-
1. Either first fit or best fit policy (any one)
2. First fit but not best fit policy
3. Best fit but not first fit policy
4. None of the above

Solution-

The allocation follows variable size partitioning scheme.

Let us say the given processes are-


 Process P1 = 300 units
 Process P2 = 25 units
 Process P3 = 125 units
 Process P4 = 50 units

Allocation Using First Fit Algorithm-

The allocation of partitions to the given processes is shown below-

Step-01:

Step-02:

Step-03:

Step-04:
Allocation Using Best Fit Algorithm-

The allocation of partitions to the given processes is shown below-

Step-01:

Step-02:

Step-03:

Step-04:

 Process P4 can not be allocated the memory.


 This is because no partition of size greater than or equal to the size of process P4 is available.

Thus,
 Only first fit allocation policy succeeds in allocating memory to all the processes.
 Option (B) is correct.

Consider a memory system with a cache access time of 10ns and a memory access time
of 110ns assume the memory access time includes the time to check the cache. If the
effective access time is 10% greater than the cache access time, what is the hit ratio H?
AU CSE: May-17
Ans. Effective Access Time = H × Tcache + (1-H) × Tmemory
1.1 × Tcache = H × Tcache + (1-H) × Tmemory
1.1 × 10 = H × 10 + (1 - H) 110
11 = H × 10 + 110 - 110 × H
- 99 = -100 H
H = 99/100
H = 0.99

Consider the following page-reference string 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12. How many
page faults ratio would occur for the FIFO page replacement algorithm? Assuming
three is four frames.

page faults = 12 page faults ratio = 100%

Consider the following segmentation table.

What are the physical addresses for the logical addresses 3400 and 0110? AU CSE/IT:
May-19
Ans. :
Logical address 3,400 :
Segment = 3, offset = 400, length = 580
Physical address = offset + base = 400 + 1327
Physical address = 1727
Logical address 0, 110:
Segment = 0, offset = 110, length = 600
Physical address = offset + base = 110 + 219
Physical addrres = 329

You might also like