498 views
1 1 vote

A system uses a modified Counting Semaphore $S$ to manage access to a pool of 3 identical resources. The semaphore is initialized to $S=3$. The $\verb|Wait (S)|$ and $\verb|Signal(S)|$ operations are redefined to prioritize processes based on their Priority Level $(L)$, where a higher $L$ means higher priority.

  • $\verb|WAIT(S, L)|:$ If $S>0, S=S-1$. If $S=0$, the process enters a Priority Queue $Q$ sorted by $L$.
     
  • $\verb|SIGNAL(S)|:$ If $Q$ is empty, $S=S+1$. If $Q$ is not empty, the process with the highest priority $L$ in $Q$ is woken up and immediately consumes the resource $(S$ remains $0)$.

Consider five processes $\left\{P_1, P_2, P_3, P_4, P_5\right\}$ with Priority Levels $\{10,20,30,40,50\}$ respectively. They arrive in the following order:

1. $P_1, P_2, P_3$ arrive and successfully execute $\verb|Wait|$.

2. $P_4$ and $P_5$ arrive and execute $\verb|Wait|$, entering queue $Q$.

3. $P_1$ executes $\verb|Signal|$.

4. A new process $P_6$ with Priority Level $L=100$ arrives and executes $\verb|Wait|$.
 

Which one of the following is TRUE regarding this scenario?

  1. $P_4$ WILL ACQUIRE THE RESOURCE AFTER $P_1$ SIGNALS, REGARDLESS OF $P_6$.
     
  2. $P_5$ WILL ACQUIRE THE RESOURCE AFTER $P_1$ SIGNALS, BUT $P_6$ MAY CAUSE $P_4$ TO STARVE.
     
  3. $P_6$ WILL ACQUIRE THE RESOURCE IMMEDIATELY AFTER $P_1$ SIGNALS, BYPASSING $P_4$ AND $P_5$.
     
  4. THE SYSTEM IS GUARANTEED TO BE STARVATION-FREE BECAUSE THE QUEUE IS SORTED.

2 Answers

0 0 votes

1. Initial State:

  • $S=3 ~(3$ resources available$)$.
     
  • $Q=\emptyset$ (Empty).
     

2. $P_1, P_2, P_3$ arrive and execute $\verb|Wait|$ :

  • All three find $S>0$.
     
  • $S$ decrements three times: $3 \rightarrow 2 \rightarrow 1 \rightarrow 0$.
     
  • Current State: $S=0 . P_1, P_2, P_3$ are holding resources. $Q=\emptyset$.
     

3. $P_4(L=40)$ and $P_5(L=50)$ arrive and execute $\verb|Wait|$ :

  • $S=0$, so they cannot acquire the resource.
     
  • They enter the Priority Queue $Q$.
     
  • Since $Q$ is sorted by $L$ : $Q=\left[P_5(50), P_4(40)\right]$.
     
  • Current State: $S=0 . Q=\left\{P_5, P_4\right\}$.
 

4. $P_1$ executes $\verb|Signal|$ :

  • According to the logic: "If $Q$ is not empty, the process with the highest priority $L$ in $Q$ is woken up... $S$ remains $0$."
     
  • $P_5$ has the highest priority ( $L=50$ ) in $Q$.
     
  • Result: $P_5$ is woken up and takes $P_1$ 's resource.
     
  • Current State: $S=0 . Q=\left\{P_4\right\}$.
     

5. $P_6(L=100)$ arrives and executes $\verb|Wait|$ :

  • $S=0$, so $P_6$ must enter the queue $Q$.
     
  • Since $Q$ is sorted by $L$ and $P_6$ has priority $100$, it moves to the front of the queue.
     
  • Current State: $S=0 . Q=\left[P_6(100), P_4(40)\right]$.
     

A is False: $P_5$ (Priority 50) acquired the resource after $P_1$ signaled, not $P_4$.

B is True: $P_5$ acquired the resource because it was at the head of the queue when $P_1$ signaled. However, because $P_6$ arrived with a higher priority than $P_4, P_6$ will be the next to wake up when $P_2$ or $P_3$ signals. If more high-priority processes $(P_7, P_8 \ldots)$ continue to arrive, $P_4$ will stay in the queue indefinitely.

C is False: $P_6$ enters the queue. It must wait for the next $\verb|Signal|$ event $($from $P_2, P_3$, or $P_5)$ to acquire a resource. It cannot "snatch" the resource from $P_5$ during $P_1$ 's signal.

D is False: Strict priority queues are a classic cause of Starvation for low-priority processes.

Answer:
Position:
Show:

Related questions

3 3 votes
2 2 answers
407
407 views
GO Classes asked Dec 29, 2025
407 views
A system uses a Buddy System memory allocator to manage a $\mathbf{1 0 2 4}$ KB physical memory space. The system currently has three active processes allocated as follow...
2 2 votes
1 1 answer
266
266 views
GO Classes asked Dec 29, 2025
266 views
A storage server uses a Single-Level Indexed Allocation scheme. The disk parameters and file requirements are as follows:Disk Capacity $: \mathbf{128 ~ GB}$. Block Size $...
1 1 vote
1 1 answer
291
291 views
GO Classes asked Dec 29, 2025
291 views
A system manages resources that can be held in two modes: EXCLUSIVE (only one process) or SHARED (multiple processes, but they can only read, not write).When a process $P...
1 1 vote
2 2 answers
350
350 views
GO Classes asked Dec 29, 2025
350 views
A new OS uses a hybrid prevention scheme to manage a single non-preemptable resource. Each process $P_i$ has a Fixed Priority $\operatorname{Pri}\left(P_i\right)$ and a U...