CS FundamentalsModerateHCL · Tech Mahindra pattern

A counting semaphore S is initialised to 5. Then 7 wait (P) operations and 3 signal (V) operations are performed on it in some order. What is the final value of S (using the definition where S may go negative)?

  1. A. −2
  2. B. 2
  3. C. 15
  4. D. 1

Correct answer: D. 1

Each P subtracts 1 and each V adds 1: 5 − 7 + 3 = 1. The order affects which processes block on the way, not the final value.

More Operating Systems questions

Exams that ask this topic