416 views
3 3 votes

A counting semaphore $\verb|S|$ is initialized to $3.$

Five identical processes $\text{P1}-\text{P5}$ execute the following code concurrently:

wait(S);
/* critical section */
signal(S);

Assume no process terminates inside the critical section.

Which of the following statements is/are correct?

  1. At most $3$ processes can be in the critical section at any time
     
  2. Deadlock is possible
     
  3. Starvation is possible if semaphore scheduling is unfair
     
  4. Exactly $3$ processes will always be in the critical section

2 Answers

1 1 vote

The semaphore $\verb|S|$ is initialized to $3$ , so at most $3 ~\verb|wait(S)|$ operations can succeed simultaneously. Hence, at most $3$ processes can be in the critical section at any time.
Option A is correct.

Deadlock is not possible because every process that enters the critical section eventually executes $\verb|signal(S)|$, and there is no circular wait.
Option B is false.

Starvation is possible if the semaphore implementation uses unfair scheduling. A process may remain waiting indefinitely while others repeatedly enter the critical section.
Option C is correct.

It is not guaranteed that exactly 3 processes will always be in the critical section, since fewer than $3$ may be executing or ready at some times.
Option D is false.

Correct options: A, C

Answer:
Position:
Show:

Related questions

2 2 votes
2 2 answers
361
361 views
GO Classes asked Dec 24, 2025
361 views
Two processes $\text{P1}$ and $\text{P2}$ share two semaphores $\verb|S|$ and $\verb|T|$, both initialized to $1$.The code executed by the processes is:$\textbf{P1} : $wa...
3 3 votes
2 2 answers
466
466 views
GO Classes asked Dec 24, 2025
466 views
Consider the following C program executed on a UNIX-like system: #include <stdio.h #include <unistd.h int main() { int x = 1; if (fork() && fork()) { ...
4 4 votes
3 3 answers
370
370 views
GO Classes asked Dec 24, 2025
370 views
A system uses paging with the following parameters:Logical address space size $=64 \mathrm{~KB}$ Page size $=1 \mathrm{~KB}$ Physical memory size $=32 \mathrm{~KB}$ Page ...
6 6 votes
2 2 answers
381
381 views
GO Classes asked Dec 24, 2025
381 views
A demand-paged system has the following characteristics:Memory access time $\mathrm{= 200 ~ns}$ Page fault service time $=10 \mathrm{~ms}$ Probability of a page fault $\m...