Operating systems miscellaneous
- The P and V operations on counting semaphores, where s is a counting semaphore, and defined as follows P(s): s = s – 1;
if s < 0 then wait;
V(s): s = s + 1;
if s < = 0 then we ke up 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 (Yb);
s = s + 1;
if (s < = 0) Vb (Yb);
Vb (Xb);
The initial values of Xb and Yb are respectively
-
View Hint View Answer Discuss in Forum
From the given code we get that P(S) and V(S), decrement and increment the value of semaphore respectively. So, from the given conditions we conclude that to avoid mutual exclusion in the value of Xb should be 1 and that of Yb should be 0.
Correct Option: C
From the given code we get that P(S) and V(S), decrement and increment the value of semaphore respectively. So, from the given conditions we conclude that to avoid mutual exclusion in the value of Xb should be 1 and that of Yb should be 0.
- The following program consist of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0 = 1, S1 = 0, S2 = 0
How many times will process P print ‘0’?
-
View Hint View Answer Discuss in Forum
P0 uses a semaphore. Hence, anything whose value is 1, P0 will print ‘0’. After the release of S1 and S2, we observe that either P1 or P2 will release S0 so that it print ‘0’ at least 2 times.
Therefore, it is concluded that neither P1 nor P2 will go, it is the P0 that prints ‘0’ 2 times atleast.Correct Option: A
P0 uses a semaphore. Hence, anything whose value is 1, P0 will print ‘0’. After the release of S1 and S2, we observe that either P1 or P2 will release S0 so that it print ‘0’ at least 2 times.
Therefore, it is concluded that neither P1 nor P2 will go, it is the P0 that prints ‘0’ 2 times atleast.
- 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?
-
View Hint View Answer Discuss in Forum
Three concurrent processes X, Y and Z execute three different code segments that access and update certain shared variables.
(a) X : P(a) P(b) P(c)
Y : P(b) P(c) P(d)
Z : P(c) P(d) P(a)
Suppose X first executes P(a) and P(b) and then switches to process Z, where P(c) and P(d) are executed and wait for P(a), Then again process switches to X and then wait for P(c).
∴ Process X is waiting for C which is occupied by Z and Z is waiting for a which is occupied by process X. So, neither can execute and deadlock occurs. (Not Acceptable)
(b) X : P(b) P(a) P(c)
Y : P(b) P(c) P(d)
Z : P(a) P(c) P(d)
Execution can be carried out in a proper way without deadlock occurance and no wait for any variable in the processer. (Acceptable)
(c) X : P(b) P(a) P(c)
Y : P(c) P(b) P(d)
Z : P(a) P(c) P(d)
The sequence of variable P(b) and P(c) are reverse and opposite [i.e., P(b) P(c) P(a) and P(a) P(b) P(c)] So, deadlock may occurs in X and Y respectively (Not Acceptable)
(d)
X : P(a) P(b) P(c)
Y : P(c) P(b) P(d)
Z : P(c) P(d) P(a)
The sequence of variable P(c) and P(a) are opposite in Z and X. So, deadlock may occur (Not Acceptable) Hence, the answer is (b).Correct Option: B
Three concurrent processes X, Y and Z execute three different code segments that access and update certain shared variables.
(a) X : P(a) P(b) P(c)
Y : P(b) P(c) P(d)
Z : P(c) P(d) P(a)
Suppose X first executes P(a) and P(b) and then switches to process Z, where P(c) and P(d) are executed and wait for P(a), Then again process switches to X and then wait for P(c).
∴ Process X is waiting for C which is occupied by Z and Z is waiting for a which is occupied by process X. So, neither can execute and deadlock occurs. (Not Acceptable)
(b) X : P(b) P(a) P(c)
Y : P(b) P(c) P(d)
Z : P(a) P(c) P(d)
Execution can be carried out in a proper way without deadlock occurance and no wait for any variable in the processer. (Acceptable)
(c) X : P(b) P(a) P(c)
Y : P(c) P(b) P(d)
Z : P(a) P(c) P(d)
The sequence of variable P(b) and P(c) are reverse and opposite [i.e., P(b) P(c) P(a) and P(a) P(b) P(c)] So, deadlock may occurs in X and Y respectively (Not Acceptable)
(d)
X : P(a) P(b) P(c)
Y : P(c) P(b) P(d)
Z : P(c) P(d) P(a)
The sequence of variable P(c) and P(a) are opposite in Z and X. So, deadlock may occur (Not Acceptable) Hence, the answer is (b).
- A process executes the following code for (i = 0 ; i < n; i ++) for ();
The total number of child processes created is
-
View Hint View Answer Discuss in Forum
We know that the total number of processes is 2n but we subtract the main process therefore, total number of children = 2(n – 1) .
Correct Option: B
We know that the total number of processes is 2n but we subtract the main process therefore, total number of children = 2(n – 1) .
- A single processor system has three resources types X, Y and Z, which are shared by three processes. There are 5 units of each resources type. Consider the following scenario, where the column alloc denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Which of these processes will finish last?
-
View Hint View Answer Discuss in Forum
From the given matrix we found that the number of available resources of X, Y and Z types are 0, 1, 2 respectively. Therefore, P1 will avail these resources first and after release the resources available will be (2, 1, 3) which will be used by P0 as its request is of 1, 0, 3 resources. After P0 releases the resources, the availability becomes (3, 3, 4) and P2 will use these resources then as per its requirements. Thus, P2 finishes in the last.
Correct Option: C
From the given matrix we found that the number of available resources of X, Y and Z types are 0, 1, 2 respectively. Therefore, P1 will avail these resources first and after release the resources available will be (2, 1, 3) which will be used by P0 as its request is of 1, 0, 3 resources. After P0 releases the resources, the availability becomes (3, 3, 4) and P2 will use these resources then as per its requirements. Thus, P2 finishes in the last.