Question 1
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
C
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
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
Process Management    
Discuss it


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
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)
B
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 http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf 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 http://geeksquiz.com/gate-gate-cs-2013-question-16/
Question 4
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
C
1
D
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

Process W executes S=1, x=1 but it doesn't update the x variable.

Then process Y executes S=0, it decrements x, now x= -2 and 
signal semaphore S=1

Now process Z executes s=0, x=-4, signal semaphore S=1
Now process W updates x=1, S=2

Then process X executes X=2 
So correct option is D
Question 5
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
C
1
D
2
Process Management    
Discuss it


Question 5 Explanation: 
Question 6
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);
}
A
A
B
B
C
C
D
D
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
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)
B
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 http://www.eee.metu.edu.tr/~halici/courses/442/Ch5%20Deadlocks.pdf   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 http://geeksquiz.com/operating-systems-process-management-question-8/
Question 8
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
C
1
D
2
Process Management    GATE CS 2013    
Discuss it


Question 8 Explanation: 
Background Explanation: A critical section in which the process may be changing common variables, updating table, writing a file and perform another function. The important problem is that if one process is executing in its critical section, no other process is to be allowed to execute in its critical section. Each process much request permission to enter its critical section. A semaphore is a tool for synchronization and it is used to remove the critical section problem which is that no two processes can run simultaneously together so to remove this two signal operations are used named as wait and signal which is used to remove the mutual exclusion of the critical section. as an unsigned one of the most important synchronization primitives, because you can build many other Decrementing the semaphore is called acquiring or locking it, incrementing is called releasing or unlocking. Solution : Since initial value of semaphore is 2, two processes can enter critical section at a time- this is bad and we can see why. Say, X and Y be the processes.X increments x by 1 and Z decrements x by 2. Now, Z stores back and after this X stores back. So, final value of x is 1 and not -1 and two Signal operations make the semaphore value 2 again. So, now W and Z can also execute like this and the value of x can be 2 which is the maximum possible in any order of execution of the processes. (If the semaphore is initialized to 1, processed would execute correctly and we get the final value of x as -2.) Option (D) is the correct answer. Another Solution: Processes can run in many ways, below is one of the cases in which x attains max value Semaphore S is initialized to 2 Process W executes S=1, x=1 but it doesn't update the x variable. Then process Y executes S=0, it decrements x, now x= -2 and signal semaphore S=1 Now process Z executes s=0, x=-4, signal semaphore S=1 Now process W updates x=1, S=2 Then process X executes X=2 So correct option is D Another Solution: S is a counting semaphore initialized to 2 i.e., Two process can go inside a critical section protected by S. W, X read the variable, increment by 1 and write it back. Y, Z can read the variable, decrement by 2 and write it back. Whenever Y or Z runs the count gets decreased by 2. So, to have the maximum sum, we should copy the variable into one of the processes which increases the count, and at the same time the decrementing processed should run parallel, so that whatever they write back into memory can be overridden by incrementing process. So, in effect decrement would never happen.

Related Links: http://quiz.geeksforgeeks.org/process-synchronization-set-1/ http://geeksquiz.com/operating-systems-process-management-question-11/ for explanation This solution is contributed by Nitika Bansal
Question 9
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);
}
A
A
B
B
C
C
D
D
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 http://geeksquiz.com/operating-systems-process-management-question-13/
Question 10
A process executes the code
fork();
fork();
fork(); 
The total number of child processes created is
A
3
B
4
C
7
D
8
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

       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.
Question 11
Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.
  AcquireLock(L){
         while (Fetch_And_Add(L,1))
               L = 1;
   }
  ReleaseLock(L){
         L = 0;
   }
This implementation
A
fails as L can overflow
B
fails as L can take on a non-zero value when the lock is actually available
C
works correctly but may starve some processes
D
works correctly without starvation
GATE CS 2012    Process Management    
Discuss it


Question 11 Explanation: 
Take closer look the below while loop.
     while (Fetch_And_Add(L,1))
               L = 1;  // A waiting process can be here just after 
                       // the lock is released, and can make L = 1.
Consider a situation where a process has just released the lock and made L = 0. Let there be one more process waiting for the lock, means executing the AcquireLock() function. Just after the L was made 0, let the waiting processes executed the line L = 1. Now, the lock is available and L = 1. Since L is 1, the waiting process (and any other future coming processes) can not come out of the while loop. The above problem can be resolved by changing the AcuireLock() to following.
  AcquireLock(L){
         while (Fetch_And_Add(L,1))
         { // Do Nothing }
   }

Source :  http://www.geeksforgeeks.org/operating-systems-set-17/

Question 12
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
C
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 switches or Context switches can occur in only kernel mode . So for process switches first we have to move from user to kernel mode . Then we have to save the PCB of the process from which we are taking off CPU and then we have to load PCB of the required process . At switching from kernel to user mode is done. But switching from user to kernel mode is a very fast operation(OS has to just change single bit at hardware level) Thus T1< T2 This explanation has been contributed by Abhishek Kumar.
Question 13
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
C
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. A thread is a basic unit of CPU utilization, consisting of a program counter, a stack, and a set of registers, (and a thread ID.) As you can see, for a single thread of control - there is one program counter, and one sequence of instructions that can be carried out at any given time and for multi-threaded applications-there are multiple threads within a single process, each having their own program counter, stack and set of registers, but sharing common code, data, and certain structures such as open files. nitika_58 Option (A): as you can see in the above diagram, NOT ONLY CPU Register but stack and code files, data files are also maintained. So, option (A) is not correct as it says OS maintains only CPU register state. Option (B): according to option (B), OS does not maintain a separate stack for each thread. But as you can see in above diagram, for each thread, separate stack is maintained. So this option is also incorrect. Option (C): according to option (C), the OS does not maintain virtual memory state. And It is correct as Os does not maintain any virtual memory state for individual thread. Option (D): according to option (D), the OS maintains only scheduling and accounting information. But it is not correct as it contains other information like cpu registers stack, program counters, data files, code files are also maintained. Reference: https://www.cs.uic.edu/~jbell/CourseNotes/OperatingSystems/4_Threads.html This solution is contributed by Nitika Bansal
Question 14
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
Process Management    GATE CS 2010    
Discuss it


Question 14 Explanation: 
Mutual Exclusion: A way of making sure that if one process is using a shared modifiable data, the other processes will be excluded from doing the same thing. while one process executes the shared variable, all other processes desiring to do so at the same time moment should be kept waiting; when that process has finished executing the shared variable, one of the processes waiting; while that process has finished executing the shared variable, one of the processes waiting to do so should be allowed to proceed. In this fashion, each process executing the shared data (variables) excludes all others from doing so simultaneously. This is called Mutual Exclusion. Progress Requirement: If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely. Solution: 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. But here Progress Requirement is not satisfied. Suppose when s1=1 and s2=0 and process p1 is not interested to enter into critical section but p2 want to enter critical section. P2 is not able to enter critical section in this as only when p1 finishes execution, then only p2 can enter (then only s1 = s2 condition be satisfied). Progress will not be satisfied when any process which is not interested to enter into the critical section will not allow other interested process to enter into the critical section. Reference : http://www.personal.kent.edu/~rmuhamma/OpSystems/Myos/mutualExclu.htm See http://www.geeksforgeeks.org/operating-systems-set-7/ This solution is contributed by Nitika Bansal
Question 15
The following program consists of 3 concurrent processes and 3 binary semaphores.The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0. gatecs201042 How many times will process P0 print '0'?
A
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
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
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
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
Process Management    GATE CS 2008    
Discuss it


Question 17 Explanation: 
Suppose Xb = 0, then because of P(s): Pb(Xb) operation, Xb will be -1 and processs will get blocked as it will enter into waiting section. So, Xb will be one. Suppose s=2(means 2 process are accessing shared resource), taking Xb as 1,
first P(s): Pb(Xb) operation will make Xb as zero. s will be 1 and Then Vb(Xb) operation will be executed which will increase the count of Xb as one. Then same process will be repeated making Xb as one and s as zero.
Now suppose one more process comes, then Xb will be 1 but s will be -1 which will make this process go into loop (s <0) and will result into calling Vb(Xb) and Pb(Yb) operations. Vb(Xb) will result into Xb as 2 and Pb(Yb) will result into decrementing the value of Yb.
case 1: if Yb has value as 0, it will be -1 and it will go into waiting and will be blocked.total 2 process will access shared resource (according to counting semaphore, max 3 process can access shared resource) and value of s is -1 means only 1 process will be waiting for resources and just now, one process got blocked. So it is still true.
case 2: if Yb has value as 1, it will be 0. Total 3 process will access shared resource (according to counting semaphore, max 3 process can access shared resource) and value of s is -1 means only 1 process will be waiting for resources and but there is no process waiting for resources.So it is false.
See Question 2 of http://www.geeksforgeeks.org/operating-systems-set-10/ This solution is contributed by Nitika Bansal
Question 18
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;
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
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.
Process Management    GATE-CS-2007    
Discuss it


Question 19 Explanation: 
Kernel level threads are managed by the OS, therefore, thread operations are implemented in the kernel code. Kernel level threads can also utilize multiprocessor systems by splitting threads on different processors. If one thread blocks it does not cause the entire process to block. Kernel level threads have disadvantages as well. They are slower than user level threads due to the management overhead. Kernel level context switch involves more steps than just saving some registers. Finally, they are not portable because the implementation is operating system dependent. option (A): Context switch time is longer for kernel level threads than for user level threads. True, As User level threads are managed by user and Kernel level threads are managed by OS. There are many overheads involved in Kernel level thread management, which are not present in User level thread management. So context switch time is longer for kernel level threads than for user level threads. Option (B): User level threads do not need any hardware support True, as User level threads are managed by user and implemented by Libraries, User level threads do not need any hardware support. Option (C): Related kernel level threads can be scheduled on different processors in a multi- processor system. This is true. Option (D): Blocking one kernel level thread blocks all related threads. false, since kernel level threads are managed by operating system, if one thread blocks, it does not cause all threads or entire process to block. See Question 4 of http://www.geeksforgeeks.org/operating-systems-set-13/ Reference: http://www.personal.kent.edu/~rmuhamma/OpSystems/Myos/threads.htm http://quiz.geeksforgeeks.org/operating-system-user-level-thread-vs-kernel-level-thread/ This solution is contributed by Nitika Bansal
Question 20
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.
D
It does not prevent deadlocks, but ensures mutual exclusion.
Process Management    GATE-CS-2007    
Discuss it


Question 20 Explanation: 
Bounded waiting :There exists a bound, or limit, on the number of times other processes are allowed to enter their critical sections after a process has made request to enter its critical section and before that request is granted. mutual exclusion prevents simultaneous access to a shared resource. This concept is used in concurrent programming with a critical section, a piece of code in which processes or threads access a shared resource. Solution: Two processes, P1 and P2, need to access a critical section of code. Here, wants1 and wants2 are shared variables, which are initialized to false. Now, when both wants1 and wants2 become true, both process p1 and p2 enter in while loop and waiting for each other to finish. This while loop run indefinitely which leads to deadlock. Now, Assume P1 is in critical section (it means wants1=true, wants2 can be anything, true or false). So this ensures that p2 won’t enter in critical section and vice versa. This satisfies the property of mutual exclusion. Here bounded waiting condition is also satisfied as there is a bound on the number of process which gets access to critical section after a process request access to it. See question 3 of http://www.geeksforgeeks.org/operating-systems-set-13/ This solution is contributed by Nitika Bansal
Question 21
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.
C
Context switching between user level threads is faster than context switching between kernel level threads.
D
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 processes. kernel threads are implemented by OS.
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 operation then entire process will be blocked. If one kernel thread perform blocking operation then another thread can continue execution.
Example : Java thread, POSIX threads. Example : Window Solaris.
Source: http://geeksquiz.com/operating-system-user-level-thread-vs-kernel-level-thread/
Question 22
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 _________.
A
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 

Let clock period for P2 be t.

Now consider following equation based on specification
7.5 ns = 12*t ns

We get t and inverse of t will be 1.6GHz 
Question 23
Consider the procedure below for the Producer-Consumer problem which uses semaphores: GATECS2014Q30 Which 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.
C
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
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?
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
Process Management    GATE-CS-2006    
Discuss it


Question 24 Explanation: 
Question 25
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
B
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
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--
B
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).
 
Thus, option (B) is correct.
 
Please comment below if you find anything wrong in the above post.
Question 27
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)
D
P(SX), P(SY); P(SX), P(SY)
Process Management    GATE-CS-2004    
Discuss it


Question 27 Explanation: 
Option A: In line L1 ( p(Sy) ) i.e. process p1 wants lock on Sy that is 
held by process p2 and line L3 (p(Sx)) p2 wants lock on Sx which held by p1. 
So here circular and wait condition exist means deadlock.
Option B : In line L1 ( p(Sx) ) i.e. process p1 wants lock on Sx that is held 
by process p2 and line L3 (p(Sy)) p2 wants lock on Sx which held by p1. So here 
circular and wait condition exist means deadlock.
Option C: In line L1 ( p(Sx) ) i.e. process p1 wants lock on Sx and line L3 (p(Sy)) 
p2 wants lock on Sx . But Sx and Sy can’t be released by its processes p1 and p2.
Please read the following to learn more about process synchronization and semaphores: Process Synchronization Set 1 This explanation has been contributed by Dheerendra Singh.
Question 28
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
B
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 … .
 
Thus, B is the correct choice.
 
Please comment below if you find anything wrong in the above post.
Question 29
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
C
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++ ; }

 
Initially S = 1 and T = 0 to support mutual exclusion in process ‘P’ and ‘Q’.
Since, S = 1 , process ‘P’ will be executed and function Wait(S) will decrement the value of ‘S’. So, S = 0 now.
Simultaneously, in process ‘Q’ , 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 function V(T).
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
Which of the following does not interrupt a running process?
A
A device
B
Timer
C
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: http://www.geeksforgeeks.org/operating-systems-set-3/
Question 31
Which of the following need not necessarily be saved on a context switch between processes?
A
General purpose registers
B
Translation look aside buffer
C
Program counter
D
All of the above
Process Management    GATE-CS-2000    
Discuss it


Question 31 Explanation: 
Question 32
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
A
3
B
2
C
5
D
4
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
Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes. Q20 Here, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?
A
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 true.So, 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 happen.Hence, answer is A.
Question 34
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?
A
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 KILLED.So,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
A process executes the following segment of code :
 for(i = 1; i < = n; i++)

fork (); 
The number of new processes created is  
A
n
B
((n(n + 1))/2)
C
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

       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 2n – 1 child processes. Also see this post for more details.
Question 36
The semaphore variables full, empty and mutex are initialized to 0, n and 1, respectively. Process P1 repeatedly adds one item at a time to a buffer of size n, and process Prepeatedly removes one item at a time from the same buffer using the programs given below. In the programs, K, L, M and N are unspecified statements.
 P1
while (1) {     K; P(mutex); Add an item to the buffer; V(mutex);     L; } P2 while (1) {    M; P(mutex); Remove an item from the buffer; V(mutex);     N; } The statements K, L, M and N are respectively
A
P(full), V(empty), P(full), V(empty)
B
P(full), V(empty), P(empty), V(full)
C
P(empty), V(full), P(empty), V(full)
D
P(empty), V(full), P(full), V(empty)
Process Management    GATE-IT-2004    
Discuss it


Question 36 Explanation: 

Process P1 is the producer and process P2 is the consumer.
Semaphore ‘full’ is initialized to '0'. This means there is no item in the buffer. Semaphore ‘empty’ is initialized to 'n'. This means there is space for n items in the buffer.
In process P1, wait on semaphore 'empty' signifies that if there is no space in buffer then P1 can not produce more items. Signal on semaphore 'full' is to signify that one item has been added to the buffer.
In process P2, wait on semaphore 'full' signifies that if the buffer is empty then consumer can’t not consume any item. Signal on semaphore 'empty' increments a space in the buffer after consumption of an item.
 
Thus, option (D) is correct.
 
Please comment below if you find anything wrong in the above post.
Question 37
Consider the following two-process synchronization solution. y1 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.
C
This solution violates progress requirement.
D
This solution violates bounded wait requirement.
Process Management    GATE-CS-2016 (Set 2)    
Discuss it


Question 37 Explanation: 
It satisfies the mutual excluision : 
Process P0 and P1 could not have successfully executed their while 
statements at the same time as value of ‘turn’ can either be 0 or 1 
but can’t be both at the same time. Lets say, when process P0 executing 
its while statements with the condition “turn == 1”, So this condition 
will persist as long as process P1 is executing its critical section. And 
when P1 comes out from its critical section it changes the value of  ‘turn’ 
to 0 in exit section and because of that time P0 comes out from the its while 
loop and enters into its critical section. Therefore only one process is 
able to execute its critical section at a time.
Its also satisfies bounded waiting : 
It is limit on number of times that other process is allowed to enter its
 critical section after a process has made a request to enter its critical 
section and before that request is granted. Lets say, P0 wishes to enter into
 its critical section, it will definitely get a chance to enter into its critical
 section after at most one entry made by p1 as after executing its critical section
 it will set ‘turn’ to 0 (zero). And vice-versa (strict alteration).
Progess is not satisfied : 
Because of strict alternation no process can stop other process from entering into 
its critical section.
This explanation has been contributed by Dheerendra Singh.
Question 38
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 ________.
A
7
B
8
C
9
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
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
C
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
In the working-set strategy, which of the following is done by the operating system to prevent thrashing?
  1. It initiates another process if there are enough extra frames.
  2. It selects a process to suspend if the sum of the sizes of the working-sets exceeds the total number of available frames.
 
A
I only
B
II only
C
Neither I nor II
D
Both I and II
Process Management    GATE IT 2006    
Discuss it


Question 40 Explanation: 
According to concept of thrashing,
  • I is true because to prevent thrashing we must provide processes with as many frames as they really need "right now".If there are enough extra frames, another process can be initiated.
  • II is true because The total demand, D, is the sum of the sizes of the working sets for all processes. If D exceeds the total number of available frames, then at least one process is thrashing, because there are not enough frames available to satisfy its minimum working set. If D is significantly less than the currently available frames, then additional processes can be launched.
Question 41
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
C
(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: 
2007_9
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
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
D
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: 
A semaphore is hardware or a software tag variable whose value indicates the status of a common resource. Its purpose is to lock the resource being used. A process which needs the resource will check the semaphore for determining the status of the resource followed by the decision for proceeding. In multitasking operating systems, the activities are synchronized by using the semaphore techniques. wait and signal are defined on the semaphore. Entry to the critical section is controlled by the wait operation and exit from a critical region is taken care by signal operation. The wait, signal operations are also called P and V operations. The manipulation of semaphore (S) takes place as following: 1. The wait command P(S) decrements the semaphore value by 1. If the resulting value becomes negative then P command is delayed until the condition is satisfied. 2. The V(S) i.e. signals operation increments the semaphore value by 1. Solution: Consumer can consume only once the producer has produced the item, and producer can produce(except the first time) only once the consumer has consumed the item. Let’s explain the working of this code. It is mentioned that Producer and Consumer execute parallely. Producer: st1 - S value is 1, P(S) on S makes it 0 and st2 - and then x item is produced. st3 - Q value is 0. V(Q) on Q makes it 1. this being an infinite while loop should infinitely iterate. In the next iteration of while loop, S is already 0 ,further P(S) on 0 sends P to blocked list of S. So producer is blocked. Consumer: P(Q) on Q makes Q =0 and then consumes the item. V(S) on S, now instead of changing the value of S to 1,consumer wakes up the blocked process on Q 's queue. Hence process P is awaken. P resumes from st2,since it was blocked at statement 1. So P now produces the next item. So consumer consumes an item before producer produces the next item. Correct Option is (D). Choice of this question: A) deadlock cannot happen has both producer and consumer are operating on different semaphores (no hold and wait ) B) No starvation happen because there is alteration between P and Consumer Which also makes them have bounded waiting. (C) Some of the items produced by the producer may be lost but it can’t.
Reference: http://www.geeksforgeeks.org/mutex-vs-semaphore/
This solution is contributed by Nitika Bansal
Question 43
An operating system implements a policy that requires a process to release all resources before making a request for another resource. Select the TRUE statement from the following:
A
Both starvation and deadlock can occur
B
Starvation can occur but deadlock cannot occur
C
Starvation cannot occur but deadlock can occur
D
Neither starvation nor deadlock can occur
Process Management    Gate IT 2008    
Discuss it


Question 43 Explanation: 
Starvation may occur, as a process may want othe resource in ||<sup>al</sup> along with currently hold resources. <br> According to given conditions it will never be possible to collect all at a time.<br> No deadlock.
Question 44
If the time-slice used in the round-robin scheduling policy is more than the maximum time required to execute any process, then the policy will
A
degenerate to shortest job first
B
degenerate to priority scheduling
C
degenerate to first come first serve
D
none of the above
Process Management    Gate IT 2008    
Discuss it


Question 44 Explanation: 
RR executes processes in FCFS manner with a time slice. It this time slice becomes long enough, so that a process finishes within it, It becomes FCFS.
Question 45
Consider the following C code for process P1 and P2. a=4, b=0, c=0 (initialization)
     P1                      P2
  if (a < 0)                b = 10;    
    c = b-a;                a = -3;
  else
    c = b+a;
If the processes P1 and P2 executes concurrently (shared variables a, b and c), which of the following cannot be the value of ‘c’ after both processes complete?
A
4
B
7
C
10
D
13
Process Management    GATE 2017 Mock    
Discuss it


Question 45 Explanation: 
P1 : 1, 3, 4 -> c = 0+4 =4 {hence option a}
P2 : i, ii and P1 : 1, 2 -> c = 10-(-3) = 13 {hence option d}
P1 : 1 , P2 : i, ii and P1 : 3, 4 -> c= 10+(-3) = 7 { hence option b}
So 10 cannot be c value.
There are 45 questions to complete.

GATE CS Corner


See Placement Course for placement preparation, GATE Corner for GATE CS Preparation and Quiz Corner for all Quizzes on GeeksQuiz.