Process Management and Semaphore Operations
Process Management and Semaphore Operations
Question 1
Correct
Consider the following code fragment:
if (fork() == 0)
{ a = a + 5; printf("%d,%d\n", a, &a); }
else { a = a –5; printf("%d, %d\n", a, &a); }
Let u, v be the values printed by the parent process, and x, y be the values printed by the child
process. Which one of the following is TRUE?
A u = x + 10 and v = y
B u = x + 10 and v != y
u + 10 = x and v = y
D u + 10 = x and v != y
Process Management
Discuss it
Question 1 Explanation:
fork() returns 0 in child process and process ID of child process in parent process. In Child (x), a
= a + 5 In Parent (u), a = a – 5; Therefore x = u + 10. The physical addresses of ‘a’ in parent and
child must be different. But our program accesses virtual addresses (assuming we are running on
an OS that uses virtual memory). The child process gets an exact copy of parent process and
virtual address of ‘a’ doesn’t change in child process. Therefore, we get same addresses in both
parent and child. See this run for example.
Question 2
Correct
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);
}
Question 2 Explanation:
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().
Question 3
Correct
Three concurrent processes X, Y, and Z execute three different code segments that access and
update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a,
b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P
operation on semaphores c, d, and a before entering the respective code segments. After
completing the execution of its code segment, each process invokes the V operation (i.e., signal)
on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of
the following represents a deadlockfree order of invoking the P operations by the processes?
(GATE CS 2013)
A X: P(a)P(b)P(c) Y:P(b)P(c)P(d) Z:P(c)P(d)P(a)
X: P(b)P(a)P(c) Y:P(b)P(c)P(d) Z:P(a)P(c)P(d)
C X: P(b)P(a)P(c) Y:P(c)P(b)P(d) Z:P(a)P(c)P(d)
D X: P(a)P(b)P(c) Y:P(c)P(b)P(d) Z:P(c)P(d)P(a)
Process Management Deadlock
Discuss it
Question 3 Explanation:
Option A can cause deadlock. Imagine a situation process X has acquired a, process Y has
acquired b and process Z has acquired c and d. There is circular wait now. Option C can also
cause deadlock. Imagine a situation process X has acquired b, process Y has acquired c and
process Z has acquired a. There is circular wait now. Option D can also cause deadlock. Imagine
a situation process X has acquired a and b, process Y has acquired c. X and Y circularly waiting
for each other. See [Link]
Consider option A) for example here all 3 processes are concurrent so X will get semaphore a, Y
will get b and Z will get c, now X is blocked for b, Y is blocked for c, Z gets d and blocked for a.
Thus it will lead to deadlock. Similarly one can figure out that for B) completion order is Z,X
then Y. This question is duplicate of [Link]
Question 4
Correct
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z
as follows. Each of the processes W and X reads x from memory, increments by one, stores it to
memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements
by two, stores it to memory, and then terminates. Each process before reading x invokes the P
operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the
semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum
possible value of x after all processes complete execution? (GATE CS 2013)
A -2
B -1
C1
2
Process Management
Discuss it
Question 4 Explanation:
Processes can run in many ways, below is one of the cases in which x attains max value
Semaphore S is initialized to 2
Question 5 Explanation:
See [Link] for explanation.
Question 6
Correct
A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and
b[i]=g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes
X and Y such that X computes the array a and Y computes the array b. The processes employ
two binary semaphores R and S, both initialized to zero. The array a is shared by the two
processes. The structures of the processes are shown below.
Process X: Process Y:
private i; private i;
for (i=0; i < n; i++) { for (i=0; i < n; i++) {
a[i] = f(i); EntryY(R, S);
ExitX(R, S); b[i]=g(a[i]);
} }
Which one of the following represents the CORRECT implementations of ExitX and EntryY?
(A)
ExitX(R, S) {
P(R);
V(S);
}
EntryY (R, S) {
P(S);
V(R);
}
(B)
ExitX(R, S) {
V(R);
V(S);
}
EntryY(R, S) {
P(R);
P(S);
}
(C)
ExitX(R, S) {
P(S);
V(R);
}
EntryY(R, S) {
V(S);
P(R);
}
(D)
ExitX(R, S) {
V(R);
P(S);
}
EntryY(R, S) {
V(S);
P(R);
}
AA
BB
C
DD
Process Management
Discuss it
Question 6 Explanation:
The purpose here is neither the deadlock should occur
nor the binary semaphores be assigned value greater
than one.
A leads to deadlock
B can increase value of semaphores b/w 1 to n
D may increase the value of semaphore R and S to
2 in some cases
Question 7
Correct
Three concurrent processes X, Y, and Z execute three different code segments that access and
update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a,
b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P
operation on semaphores c, d, and a before entering the respective code segments. After
completing the execution of its code segment, each process invokes the V operation (i.e., signal)
on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of
the following represents a deadlock-free order of invoking the P operations by the processes?
A X: P(a)P(b)P(c) Y: P(b)P(c)P(d) Z: P(c)P(d)P(a)
X: P(b)P(a)P(c) Y: P(b)P(c)P(d) Z: P(a)P(c)P(d)
C X: P(b)P(a)P(c) Y: P(c)P(b)P(d) Z: P(a)P(c)P(d)
D X: P(a)P(b)P(c) Y: P(c)P(b)P(d) Z: P(c)P(d)P(a)
Process Management GATE CS 2013
Discuss it
Question 7 Explanation:
Option A can cause deadlock. Imagine a situation process X has acquired a, process Y has
acquired b and process Z has acquired c and d. There is circular wait now. Option C can also
cause deadlock. Imagine a situation process X has acquired b, process Y has acquired c and
process Z has acquired a. There is circular wait now. Option D can also cause deadlock. Imagine
a situation process X has acquired a and b, process Y has acquired c. X and Y circularly waiting
for each other. See [Link]
Consider option A) for example here all 3 processes are concurrent so X will get semaphore a, Y
will get b and Z will get c, now X is blocked for b, Y is blocked for c, Z gets d and blocked for a.
Thus it will lead to deadlock. Similarly one can figure out that for B) completion order is Z,X
then Y. This question is duplicate of [Link]
management-question-8/
Question 8
Correct
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z
as follows. Each of the processes W and X reads x from memory, increments by one, stores it to
memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements
by two, stores it to memory, and then terminates. Each process before reading x invokes the P
operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the
semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum
possible value of x after all processes complete execution?
A -2
B -1
C1
2
Process Management GATE CS 2013
Discuss it
Question 8 Explanation:
See [Link] for explanation
Question 9
Correct
A certain computation generates two arrays a and b such that a[i]=f(i) for 0 ≤ i < n and
b[i]=g(a[i]) for 0 ≤ i < n. Suppose this computation is decomposed into two concurrent processes
X and Y such that X computes the array a and Y computes the array b. The processes employ
two binary semaphores R and S, both initialized to zero. The array a is shared by the two
processes. The structures of the processes are shown below.
Process X: Process Y:
private i; private i;
for (i=0; i < n; i++) { for (i=0; i < n; i++) {
a[i] = f(i); EntryY(R, S);
ExitX(R, S); b[i]=g(a[i]);
} }
Which one of the following represents the CORRECT implementations of ExitX and EntryY?
(A)
ExitX(R, S) {
P(R);
V(S);
}
EntryY (R, S) {
P(S);
V(R);
}
(B)
ExitX(R, S) {
V(R);
V(S);
}
EntryY(R, S) {
P(R);
P(S);
}
(C)
ExitX(R, S) {
P(S);
V(R);
}
EntryY(R, S) {
V(S);
P(R);
}
(D)
ExitX(R, S) {
V(R);
P(S);
}
EntryY(R, S) {
V(S);
P(R);
}
AA
BB
C
DD
Process Management GATE CS 2013
Discuss it
Question 9 Explanation:
The purpose here is neither the deadlock should occur
nor the binary semaphores be assigned value greater
than one.
A leads to deadlock
B can increase value of semaphores b/w 1 to n
D may increase the value of semaphore R and S to
2 in some cases
See [Link]
Question 10
Correct
A process executes the code
fork();
fork();
fork();
The total number of child processes created is
A3
B4
7
D8
GATE CS 2012 Process Management
Discuss it
Question 10 Explanation:
Let us put some label names for the three lines
fork (); // Line 1
fork (); // Line 2
fork (); // Line 3
Question 11 Explanation:
See [Link]
Question 12
Correct
The time taken to switch between user and kernel modes of execution be t1 while the time taken
to switch between two processes be t2. Which of the following is TRUE?
A t1 > t2
B t1 = t2
t1 < t2
D nothing can be said about the relation between t1 and t2
Process Management GATE CS 2011
Discuss it
Question 12 Explanation:
Process switching involves mode switch. Context switching can occur only in kernel mode.
Question 13
Correct
A thread is usually defined as a "light weight process" because an operating system (OS)
maintains smaller data structures for a thread than for a process. In relation to this, which of the
following is TRUE?
A On per-thread basis, the OS maintains only CPU register state
B The OS does not maintain a separate stack for each thread
On per-thread basis, the OS does not maintain virtual memory state
D On per-thread basis, the OS maintains only scheduling and accounting information
Process Management GATE CS 2011
Discuss it
Question 13 Explanation:
Threads share address space of Process. Virtually memory is concerned with processes not with
Threads.
Question 14
Correct
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?
Mutual exclusion but not progress
B Progress but not mutual exclusion
C Neither mutual exclusion nor progress
D Both mutual exclusion and progress
Process Management GATE CS 2010
Discuss it
Question 14 Explanation:
See [Link]
Question 15
Correct
The following program consists of 3 concurrent processes and 3 binary [Link]
semaphores are initialized as S0 = 1, S1 = 0, S2 = 0.
How many times
will process P0 print '0'?
At least twice
B Exactly twice
C Exactly thrice
D Exactly once
Process Management GATE CS 2010
Discuss it
Question 15 Explanation:
Initially only P0 can go inside the while loop as S0 = 1, S1 = 0, S2 = 0. P0 first prints '0' then,
after releasing S1 and S2, either P1 or P2 will execute and release S0. So 0 is printed again.
Question 16
Correct
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?
I only
B I and II
C II and III
D IV only
Process Management GATE-CS-2009
Discuss it
Question 16 Explanation:
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.
Question 17
Correct
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
1 and 0
D 1 and 1
Process Management GATE CS 2008
Discuss it
Question 17 Explanation:
See Question 2 of [Link]
Question 18
Correct
A process executes the following code
for (i = 0; i < n; i++) fork();
The total number of child processes created is
An
2^n - 1
C 2^n
D 2^(n+1) - 1;
Process Management GATE CS 2008
Discuss it
Question 18 Explanation:
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. Also see this post for more details.
Question 19
Correct
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.
Related kernel level threads can be scheduled on different processors in a multi-processor
C
system.
Blocking one kernel level thread blocks all related threads.
Process Management GATE-CS-2007
Discuss it
Question 19 Explanation:
See Question 4 of [Link]
Question 20
Correct
Two processes, P1 and P2, need to access a critical section of code. Consider the following
synchronization construct used by the processes:Here, wants1 and wants2 are shared variables,
which are initialized to false. Which one of the following statements is TRUE about the above
construct?v
/* P1 */
while (true) {
wants1 = true;
while (wants2 == true);
/* Critical
Section */
wants1=false;
}
/* Remainder section */
/* P2 */
while (true) {
wants2 = true;
while (wants1==true);
/* Critical
Section */
wants2 = false;
}
/* Remainder section */
A It does not ensure mutual exclusion.
B It does not ensure bounded waiting.
C It requires that processes enter the critical section in strict alternation.
It does not prevent deadlocks, but ensures mutual exclusion.
Process Management GATE-CS-2007
Discuss it
Question 20 Explanation:
See question 3 of [Link]
Question 21
Correct
Which one of the following is FALSE?
A User level threads are not scheduled by the kernel.
B When a user level thread is blocked, all other threads of its process are blocked.
Context switching between user level threads is faster than context switching between kernel
C
level threads.
Kernel level threads cannot share the code segment
Process Management GATE-CS-2014-(Set-1)
Discuss it
Question 21 Explanation:
User level thread Kernel level thread
User thread are implemented by user
kernel threads are implemented by OS.
processes.
OS doesn’t recognized user level threads. Kernel threads are recognized by OS.
Implementation of User threads is easy. Implementation of Kernel thread is complicated.
Context switch time is less. Context switch time is more.
Context switch requires no hardware support. Hardware support is needed.
If one user level thread perform blocking If one kernel thread perform blocking operation
operation then entire process will be blocked. then another thread can continue execution.
Example : Java thread, POSIX threads. Example : Window Solaris.
Source: [Link]
Question 22
Correct
Consider two processors P1 and P2 executing the same instruction set. Assume that under
identical conditions, for the same input, a program running on P2 takes 25% less time but incurs
20% more CPI (clock cycles per instruction) as compared to the program running on P1. If the
clock frequency of P1 is 1GHz, then the clock frequency of P2 (in GHz) is _________.
1.6
B 3.2
C 1.2
D 0.8
Process Management GATE-CS-2014-(Set-1)
Discuss it
Question 22 Explanation:
For P1 clock period = 1ns
Wh
ich one of the following is TRUE?
A The producer will be able to add an item to the buffer, but the consumer can never consume it.
B The consumer will remove no more than one item from the buffer.
Deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is empty.
D The starting value for the semaphore n must be 1 and not 0 for deadlock-free operation.
Process Management GATE-CS-2014-(Set-2)
Discuss it
Question 23 Explanation:
Initially, there is no element in the buffer.
Semaphore s = 1 and semaphore n = 0.
We assume that initially control goes to the consumer when buffer is empty.
semWait(s) decrements the value of semaphore ‘s’ . Now, s = 0 and semWait(n) decrements the
value of semaphore ‘n’. Since, the value of semaphore ‘n’ becomes less than 0 , the control
stucks in while loop of function semWait() and a deadlock arises.
Thus, deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is
empty.
Please comment below if you find anything wrong in the above post.
Question 24
Correct
The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and
fetches the old value of x n y without allowing any intervening access to the memory location x.
consider the following implementation of P and V functions on a binary semaphore S.
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?
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
Process Management GATE-CS-2006
Discuss it
Question 24 Explanation:
See Question 3 of [Link]
Question 25
Correct
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each
process in the set arrives at the barrier and waits for all others to arrive and then all processes
leave the barrier. Let the number of processes in the set be three and S be a binary semaphore
with the usual P and V functions. Consider the following C implementation of a barrier with line
numbers shown on left.
void barrier (void) {
1: P(S);
2: process_arrived++;
3. V(S);
4: while (process_arrived !=3);
5: P(S);
6: process_left++;
7: if (process_left==3) {
8: process_arrived = 0;
9: process_left = 0;
10: }
11: V(S);
}
The variables process_arrived and process_left are shared among all processes and are initialized
to zero. In a concurrent program all the three processes call the barrier function when they need
to synchronize globally. The above implementation of barrier is incorrect. Which one of the
following is true?
A The barrier implementation is wrong due to the use of binary semaphore S
The barrier implementation may lead to a deadlock if two barrier in invocations are used in
immediate succession.
C Lines 6 to 10 need not be inside a critical section
D The barrier implementation is correct if there are only two processes instead of three.
Process Management GATE-CS-2006
Discuss it
Question 25 Explanation:
It is possible that process_arrived becomes greater than 3. It will not be possible for process
arrived to become 3 again, hence deadlock.
Question 26
Correct
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each
process in the set arrives at the barrier and waits for all others to arrive and then all processes
leave the barrier. Let the number of processes in the set be three and S be a binary semaphore
with the usual P and V functions. Consider the following C implementation of a barrier with line
numbers shown on left.
void barrier (void) {
1: P(S);
2: process_arrived++;
3. V(S);
4: while (process_arrived !=3);
5: P(S);
6: process_left++;
7: if (process_left==3) {
8: process_arrived = 0;
9: process_left = 0;
10: }
11: V(S);
}
The variables process_arrived and process_left are shared among all processes and are initialized
to zero. In a concurrent program all the three processes call the barrier function when they need
to synchronize globally. Which one of the following rectifies the problem in the implementation?
A Lines 6 to 10 are simply replaced by process_arrived--
At the beginning of the barrier the first process to enter the barrier waits until process_arrived
becomes zero before proceeding to execute P(S).
C Context switch is disabled at the beginning of the barrier and re-enabled at the end.
D The variable process_left is made private instead of shared
Process Management GATE-CS-2006
Discuss it
Question 26 Explanation:
Step ‘2’ should not be executed when the process enters the barrier second time till other two
processes have not completed their 7th step. This is to prevent variable process_arrived
becoming greater than 3.
So, when variable process_arrived becomes zero and variable process_left also becomes zero
then the problem of deadlock will be resolved.
Thus, at the beginning of the barrier the first process to enter the barrier waits until
process_arrived becomes zero before proceeding to execute P(S).
Please comment below if you find anything wrong in the above post.
Question 27
Correct
Consider two processes P1 and P2 accessing the shared variables X and Y protected by two
binary semaphores SX and SY respectively, both initialized to 1. P and V denote the usual
semaphone operators, where P decrements the semaphore value, and V increments the
semaphore value. The pseudo-code of P1 and P2 is as follows : P1 :
While true do {
L1 : ................
L2 : ................
X = X + 1;
Y = Y - 1;
V(SX);
V(SY);
}
P2 :
While true do {
L3 : ................
L4 : ................
Y = Y + 1;
X = Y - 1;
V(SY);
V(SX);
}
In order to avoid deadlock, the correct operators at L1, L2, L3 and L4 are respectively
A P(SY), P(SX); P(SX), P(SY)
B P(SX), P(SY); P(SY), P(SX)
C P(SX), P(SX); P(SY), P(SY)
P(SX), P(SY); P(SX), P(SY)
Process Management GATE-CS-2004
Discuss it
Question 28
Correct
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S
and T. The code for the processes P and Q is shown below.
Process P:
while (1) {
W:
print '0';
print '0';
X:
}
Process Q:
while (1) {
Y:
print '1';
print '1';
Z:
}
Synchronization statements can be inserted only at points W, X, Y and Z. Which of the
following will always lead to an output staring with '001100110011' ?
A P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S initially 1, and T initially 0
C P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
D P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S initially 1, and T initially 0
Process Management GATE-CS-2003
Discuss it
Question 28 Explanation:
P(S) means wait on semaphore ‘S’ and V(S) means signal on semaphore ‘S’. 1 Wait(S) { while (i
<= 0) --S; } Signal(S) { S++; } [/sourcecode] Initially, we assume S = 1 and T = 0 to support
mutual exclusion in process P and Q. Since S = 1, only process P will be executed and wait(S)
will decrement the value of S. Therefore, S = 0. At the same instant, in process Q, value of T = 0.
Therefore, in process Q, control will be stuck in while loop till the time process P prints 00 and
increments the value of T by calling the function V(T). While the control is in process Q,
semaphore S = 0 and process P would be stuck in while loop and would not execute till the time
process Q prints 11 and makes the value of S = 1 by calling the function V(S). This whole
process will repeat to give the output 00 11 00 11 … .
Please comment below if you find anything wrong in the above post.
Question 29
Correct
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S
and T. The code for the processes P and Q is shown below.
Process P:
while (1) {
W:
print '0';
print '0';
X:
}
Process Q:
while (1) {
Y:
print '1';
print '1';
Z:
}
Synchronization statements can be inserted only at points W, X, Y and Z Which of the following
will ensure that the output string never contains a substring of the form 01n0 or 10n1 where n is
odd?
A P(S) at W, V(S) at X, P(T) at Y, V(T) at Z, S and T initially 1
B P(S) at W, V(T) at X, P(T) at Y, V(S) at Z, S and T initially 1
P(S) at W, V(S) at X, P(S) at Y, V(S) at Z, S initially 1
D V(S) at W, V(T) at X, P(S) at Y, P(T) at Z, S and T initially 1
Process Management GATE-CS-2003
Discuss it
Question 29 Explanation:
P(S) means wait on semaphore ’S’ and V(S) means signal on semaphore ‘S’. The definition of
these functions are :
Wait(S) {
while (i <= 0) ;
S-- ;
}
Signal(S) {
S++ ;
}
While the control is in process ‘Q’, S = 0 and process ‘P’ will be stuck in while loop. Process ‘P’
will not execute till the time process ‘Q’ prints ‘11’ and makes S = 1 by calling function V(S).
Thus, process 'P' and 'Q' will keep on repeating to give the output ‘00110011 …… ‘ .
Please comment below if you find anything wrong in the above post.
Question 30
Correct
Which of the following does not interrupt a running process?
A A device
B Timer
Scheduler process
D Power failure
Process Management GATE-CS-2001
Discuss it
Question 30 Explanation:
Scheduler process doesn’t interrupt any process, it’s Job is to select the processes for following
three purposes. Long-term scheduler(or job scheduler) –selects which processes should be
brought into the ready queue Short-term scheduler(or CPU scheduler) –selects which process
should be executed next and allocates CPU. Mid-term Scheduler (Swapper)- present in all
systems with virtual memory, temporarily removes processes from main memory and places
them on secondary memory (such as a disk drive) or vice versa. The mid-term scheduler may
decide to swap out a process which has not been active for some time, or a process which has a
low priority, or a process which is page faulting frequently, or a process which is taking up a
large amount of memory in order to free up main memory for other processes, swapping the
process back in later when more memory is available, or when the process has been unblocked
and is no longer waiting for a resource. Source: [Link]
systems-set-3/
Question 31
Correct
Which of the following need not necessarily be saved on a context switch between processes?
A General purpose registers
Translation look aside buffer
C Program counter
D All of the above
Process Management GATE-CS-2000
Discuss it
Question 31 Explanation:
See question 2 of [Link]
Question 32
Correct
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute
concurrently.
P1()
{
C = B – 1;
B = 2*C;
}
P2()
{
D = 2 * B;
B = D - 1;
}
The number of distinct values that B can possibly take after the execution is
3
B2
C5
D4
Process Management GATE-CS-2015 (Set 1)
Discuss it
Question 32 Explanation:
There are following ways that concurrent processes can follow.
C = B – 1; // C = 1
B = 2*C; // B = 2
D = 2 * B; // D = 4
B = D - 1; // B = 3
C = B – 1; // C = 1
D = 2 * B; // D = 4
B = D - 1; // B = 3
B = 2*C; // B = 2
C = B – 1; // C = 1
D = 2 * B; // D = 4
B = 2*C; // B = 2
B = D - 1; // B = 3
D = 2 * B; // D = 4
C = B – 1; // C = 1
B = 2*C; // B = 2
B = D - 1; // B = 3
D = 2 * B; // D = 4
B = D - 1; // B = 3
C = B – 1; // C = 2
B = 2*C; // B = 4
There are 3 different possible values of B: 2, 3 and 4.
Question 33
Correct
Two processes X and Y need to access a critical section. Consider the following synchronization
construct used by both the processes.
Here, varP and
varQ are shared variables and both are initialized to false. Which one of the following statements
is true?
The proposed solution prevents deadlock but fails to guarantee mutual exclusion
B The proposed solution guarantees mutual exclusion but fails to prevent deadlock
C The proposed solution guarantees mutual exclusion and prevents deadlock
D The proposed solution fails to prevent deadlock and fails to guarantee mutual exclusion
Process Management GATE-CS-2015 (Set 3)
Discuss it
Question 33 Explanation:
When both processes try to enter critical section simultaneously,both are allowed to do so since
both shared variables varP and varQ are [Link], clearly there is NO mutual exclusion. Also,
deadlock is prevented because mutual exclusion is one of the four conditions to be satisfied for
deadlock to [Link], answer is A.
Question 34
Correct
In a certain operating system, deadlock prevention is attempted using the following scheme.
Each process is assigned a unique timestamp, and is restarted with the same timestamp if killed.
Let Ph be the process holding a resource R, Pr be a process requesting for the same resource R,
and T(Ph) and T(Pr) be their timestamps respectively. The decision to wait or preempt one of the
processes is based on the following algorithm.
if T(Pr) < T(Ph)
then kill Pr
else wait
Which one of the following is TRUE?
The scheme is deadlock-free, but not starvation-free
B The scheme is not deadlock-free, but starvation-free
C The scheme is neither deadlock-free nor starvation-free
D The scheme is both deadlock-free and starvation-free
Process Management GATE-IT-2004
Discuss it
Question 34 Explanation:
1. This scheme is making sure that the timestamp of requesting process is always lesser than
holding process
2. The process is restarted with same timestamp if killed and that timestamp can NOT be
greater than the existing time stamp
From 1 and 2,it is clear that any new process coming having LESSER timestamp will be
[Link],NO DEADLOCK possible However, a new process will lower timestamp may
have to wait infinitely because of its LOWER timestamp(as killed process will also have same
timestamp ,as it was killed earlier).STARVATION IS Definitely POSSIBLE So Answer is A
Question 35
Correct
A process executes the following segment of code :
for(i = 1; i < = n; i++)
fork ();
The number of new processes created is
An
B ((n(n + 1))/2)
2n - 1
D 3n - 1
Process Management GATE-IT-2004
Discuss it
Question 35 Explanation:
fork (); // Line 1
fork (); // Line 2
fork (); // Line 3
.....till n
Question 36 Explanation:
Please comment below if you find anything wrong in the above post.
Question 37
Correct
Consider the following two-process synchronization solution.
The shared variable turn is initialized to zero. Which one of the following is TRUE?
A This is a correct two-process synchronization solution.
B This solution violates mutual exclusion requirement.
This solution violates progress requirement.
D This solution violates bounded wait requirement.
Process Management GATE-CS-2016 (Set 2)
Discuss it
Question 38
Correct
Consider a non-negative counting semaphore S. The operation P(S) decrements S, and V(S)
increments S. During an execution, 20 P(S) operations and 12 V(S) operations are issued in some
order. The largest initial value of S for which at least one P(S) operation will remain blocked is
________.
7
B8
C9
D 10
Process Management GATE-CS-2016 (Set 2)
Discuss it
Question 38 Explanation:
20-7 -> 13 will be in blocked state, when we perform 12 V(S) operation makes 12 more process
to get chance for execution from blocked state. So one process will be left in the queue (blocked
state) here i have considered that if a process is in under CS then it not get blocked by other
process.
Question 39
Correct
Which of the following DMA transfer modes and interrupt handling mechanisms will enable the
highest I/O band-width?
A Transparent DMA and Polling interrupts
B Cycle-stealing and Vectored interrupts
Block transfer and Vectored interrupts
D Block transfer and Polling interrupts
Process Management Input Output Systems Computer Organization and
Architecture GATE IT 2006
Discuss it
Question 40
Correct
In the working-set strategy, which of the following is done by the operating system to prevent
thrashing?
Question 41
Correct
Processes P1 and P2 use critical_flag in the following routine to achieve mutual exclusion.
Assume that critical_flag is initialized to FALSE in the main program.
get_exclusive_access ( ) { if (critical _flag == FALSE) { critical_flag = TRUE
; critical_region () ; critical_flag = FALSE; } } Consider the following statements.
i. It is possible for both P1 and P2 to access critical_region concurrently.
ii. This may lead to a deadlock.
Which of the following holds?
A (i) is false and (ii) is true
B Both (i) and (ii) are false
(i) is true and (ii) is false
D Both (i) and (ii) are true
Process Management Deadlock Gate IT 2007
Discuss it
Question 41 Explanation:
Say P1 starts first and executes statement 1, after that system context switches to P2 (before
executing statement 2), and it enters inside if statement, since the flag is still false. So now both
processes are in critical section!! so (i) is true.. (ii) is false By no way it happens that flag is true
and no process' are inside the if clause, if someone enters the critical section, it will definitely
make flag = false. So no deadlock.
Question 42
Correct
The following is a code with two threads, producer and consumer, that can run in parallel.
Further, S and Q are binary semaphores equipped with the standard P and V operations.
semaphore S = 1, Q = 0; integer x; producer: consumer: while (true) do
while (true) do P(S); P(Q); x = produce (); consume (x);
V(Q); V(S); done done Which of the following is
TRUE about the program above?
A The process can deadlock
B One of the threads can starve
C Some of the items produced by the producer may be lost
Values generated and stored in 'x' by the producer will always be consumed before the
producer can generate a new value
Process Management Gate IT 2008
Discuss it
Question 42 Explanation:
Strict alternation exists,
so, consumer has to consume the item produced by producer before producing new item.