Counting Semaphores MCQ Quiz in বাংলা - Objective Question with Answer for Counting Semaphores - বিনামূল্যে ডাউনলোড করুন [PDF]
Last updated on Mar 19, 2025
Latest Counting Semaphores MCQ Objective Questions
Top Counting Semaphores MCQ Objective Questions
Counting Semaphores Question 1:
Each of a set of n processes executes the following code using two semaphores a and b initialized to 1 and 0, respectively. Assume that count is a shared variable initialized to 0 and not used in CODE SECTION P.
CODE SECTION P
wait (a); count=count+1 ;
if (count==n) signal (b) ;
signal (a) ; wait (b) ; signal (b) ;
CODE SECTION Q
What does the code achieve?Answer (Detailed Solution Below)
Counting Semaphores Question 1 Detailed Solution
Explanation:
The key statement in the above code is wait (b). It will keep the remaining processes blocked until value on count becomes n. Once, the value of count = n, signal (b) would be executed and then a process can enter the code section Q. Thus, none of the process will execute Q until every process has executed code section P.
Stepwise Explanation:
Initialization: a=1, b=0, count= 0
There are n processes say, P1, P2, P3, ……………., Pn.
Let’s assume P1 has executed successfully the code section P and encounters the statements:
wait (a);
Now, ‘a’ becomes 0, so all the subsequent processes are blocked.
b= 0, count= 0.
count=count+1 ; [ a=0, b=0, count=1]
if (count==n) signal (b) ; [if condition not true, so statement will not be executed]
signal (a); [a= 1, b=0, count= 1. Other processes can now execute Wait(a)]
wait (b) ; [ b= -1, therefore P1 also gets blocked and statement would not be executed]
signal (b);
This statement would only run if its preceding statement is executed, which in turn would only be executed if (count==n). Therefore, none of the process would execute Q until every process has successfully executed code section P.Counting Semaphores Question 2:
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_______.
Answer (Detailed Solution Below) 7
Counting Semaphores Question 2 Detailed Solution
Concepts:
V(S): Signal will increment the semaphore variable, that is, S++.
P(S): Signal will decrement the semaphore variable., that is, S--.
Data:
Initial counting semaphore = x
Signal operation = 12 V
Wait operation = 20 P
Since at least 1 process in blocked state
Final counting semaphore (F) = -1
Formula:
F ≥ x + 20P + 12V
Calculation:
-1 ≥ x + 20(-1) + 12(+1)
∴ x ≤ 7
Therefore, largest value of initial semaphore count is 7Counting Semaphores Question 3:
What is/are the possible outputs of the below-given block of code with initial binary semaphore value is 0?
Process P1: |
Process P2: |
while(1) { V(S); print(‘1’); print(‘0’); P(S); } |
while(1) { P(S); print(‘0’); print(‘1’); V(S); } |
I. 101010101010
II. 010101010101
III.100110011001
IV. 011001100110
V. 100110101010
Answer (Detailed Solution Below)
Counting Semaphores Question 3 Detailed Solution
Initially S = 0
If P1 executes infinitely
Output: 101010101010
If P1 executes V(S), S = 1 then P2 can execute
then P2 can execute infinitely
Output 010101010
To get the third option's output here P1 will execute first V(S), S=1 then P1 execute and print 1 0,
after printing 1 and 0 we execute P2 and P(S), S=0 then print 0 1 and because of V(S), S=1 and we can similarly start for P1.
Output will be 100110011001.
To get the fourth option's output here P2 will execute first and then P1 will execute after and produces output as:-
011001100110
Similarly, other outputs could be produced.
Tips and Tricks:
If you look carefully every possible combination of 10 and 01 is possible with this code:Counting Semaphores Question 4:
In a system, counting semaphore was initialized to 10. Then 6 P (wait) operations and 4 V (signal) operations were completed on this semaphore. So _______ is the final value of the semaphore.
Answer (Detailed Solution Below)
Counting Semaphores Question 4 Detailed Solution
Concepts:
V(S): Signal will increment the semaphore variable, that is, S++.
P(S): Wait will decrement the semaphore variable., that is, S--.
Data:
Initial counting semaphore = I = 10
Wait operation = 6 P
Signal operation = 4 V
Final counting semaphore = F
Formula:
F = I + 6 × P + 4 × V
Calculation:
F = 10 + 6 × (-1) + 4(+1)
∴ F = 8
the resulting value of the semaphore is 8Counting Semaphores Question 5:
Consider a counting semaphore S. The operation P(S) performs the operation S = S – 1 and operation V(S) performs the operation V = V + 1. During program execution, 13P and 5V operation is performed in the some order. Find the number of processes in a blocked state with initial counting semaphore value 1.
Answer (Detailed Solution Below) 7
Counting Semaphores Question 5 Detailed Solution
Concepts:
V(S): Signal will increment the semaphore variable, that is, S++.
P(S): Signal will decrement the semaphore variable., that is, S--.
Data:
Initial counting semaphore = x = 1
Signal operation = 11 V
Wait operation = 17 P
n process in blocked state
Final counting semaphore (F) = -n
Formula:
n = x + 13P + 5V
Calculation:
n = 1 + 13(-1) + 5(+1)
∴ n = -7
∴ number of process in blocked state is 7Counting Semaphores Question 6:
Let x be the value of a counting semaphore at a particular time of computation. 14 signal operation 23 wait operation is performed on the counting semaphore variable. If resulting value of the semaphore is -3 then the value of x is ________.
Answer (Detailed Solution Below) 6
Counting Semaphores Question 6 Detailed Solution
Concepts:
V(S): signal operation will increment the semaphore variable, that is, S++.
P(S): wait operation will decrement the semaphore variable., that is, S--.
Calculation:
Initial counting semaphore (I) = x
Signal operation = 14 V
Wait operation = 23 P
Final counting semaphore (F) = -3
F = x + 14V + 23P
-3 = x + 14(+1) + 23(-1)
∴ x = 6Counting Semaphores Question 7:
Semaphores are used to solve the problem of:
Answer (Detailed Solution Below)
Counting Semaphores Question 7 Detailed Solution
The correct answer is both (1) and (2).
Key Points
- Semaphores are a synchronization mechanism used to control access to a common resource in a concurrent system such as a multitasking operating system.
- They are primarily used to solve the problems of mutual exclusion and process synchronization.
- Mutual exclusion ensures that only one process can access the critical section of code at a time, preventing race conditions.
- Process synchronization ensures that processes or threads are properly synchronized to avoid issues like deadlocks and ensure correct sequence of execution.
Counting Semaphores Question 8:
In design protocol of critical section problem, each process must ask permission to enter critical section in __________ code; it then executes in the critical section; once it finishes executes in the critical section it enters the __________ code. The process then enters the __________ code.
Answer (Detailed Solution Below)
Counting Semaphores Question 8 Detailed Solution
The correct answer is entry section, exit section, remainder section
Key PointsThe critical section problem is a set of rules or protocols for managing concurrent access to a resource that is shared among several processes. The protocols define that:
- Each process must ask permission to enter the critical section in the "entry section" code.
- It then executes in the "critical section" where it has exclusive access to the shared resource.
- Once it finishes execution in the critical section, it enters the "exit section" code where it signals that it has finished with the shared resource.
- The process then enters the "remainder section" code where it executes the non-critical part of its code that doesn't involve the shared resource.
So, the flow is: Entry section -> Critical section -> Exit section -> Remainder section.
Counting Semaphores Question 9:
Semaphores are used to solve the problem of
Answer (Detailed Solution Below)
Counting Semaphores Question 9 Detailed Solution
Concept:
Semaphore is used to solve the problem of process synchronization. A semaphore is a variable that has an integer value upon which two operations are defined wait and signal, which helps in solving the critical section problem.
Explanation:
Wait operation:
It decrements the semaphore value. If the value becomes negative, then the process executing the wait is blocked.
Pseudocode :
wait(s)
{
while (s <=0)
s= s-1
}
Signal operation:
It increments the semaphore value. If value is not positive, then a process blocked by wait operation is unblocked.
Pseudocode:
signal(s)
{
s= s+1
}
Hence the correct answer is option 2
Mistake Points
Option 1 and 2 both are correct.
Counting Semaphores Question 10:
Counting semaphore was initialized to 12 for a system. Then 9 P (wait) operations and 3 V (signal) operations were completed on this semaphore. So _______ is the final value of the semaphore.
Answer (Detailed Solution Below)
Counting Semaphores Question 10 Detailed Solution
Concepts:
V(S): Signal will increment the semaphore variable, that is, S++.
P(S): Signal will decrement the semaphore variable., that is, S--.
Data:
Initial counting semaphore = I = 12
Wait operation = 9 P
Signal operation = 3 V
Final counting semaphore = F
Formula:
F = I + 9 × P + 3 × V
Calculation:
F = 12 + 9 × (-1) + 3(+1)
∴ F = 6
the resulting value of the semaphore is 6