Three processes share a single counting semaphore S whose initial value is 1. All three execute wait(S) one after another, in the order P2, P1, P3. After this, P2 exits its critical section by executing signal(S), and then P1 exits by executing signal(S). What is the value of S after these five operations?
Pick an option to check yourself, or open the answer below.
Show answer & explanation
Correct answer: A. 0
Explanation
Tracing S step by step from its initial value 1: wait(S) by P2 gives S=0 and P2 enters its critical section; wait(S) by P1 gives S=-1 and P1 blocks in the semaphore's queue; wait(S) by P3 gives S=-2 and P3 also blocks. P2 then calls signal(S), giving S=-1 and waking P1 (which now enters its critical section); P1 then calls signal(S), giving S=0 and waking P3. So after these three wait() and two signal() calls, S = 1 − 3 + 2 = 0, option (i). Note that P3 is still inside its critical section at this point — it has not yet executed its own signal(S).More System Software and Operating System questions
- In the UNIX operating system, when a process creates a child process using the fork() system call, which of the following is genuinely shar…
- A system has 12 instances of a resource R shared among four processes. The maximum need and current allocation of each process are: Process…
- Given 4 GB (≈ 4.3 × 10⁹ bytes) of virtual address space and a page size of 4 KB (= 4 × 10³ bytes), with each page table entry 5 bytes: how…
- A table T with 17 rows and 1024 columns is stored in memory. T[i][j] and the variable temp are 32-bit floating-point values; memory is word…
- Using the same table T (17 rows × 1024 columns, 32-bit word-addressable entries, 16 page frames of 1024 words each, LRU) and the same colum…
- Using the same table T (17 rows × 1024 columns, 32-bit word-addressable entries, 16 page frames of 1024 words each, LRU) and the same colum…