• edited by
17,760 views
37 37 votes

A single processor system has three resource types $X, Y$ and $Z$, which are shared by three processes. There are $5$ units of each resource type. Consider the following scenario, where the column alloc denotes the number of units of each resource type allocated to each process, and the column request denotes the number of units of each resource type requested by a process in order to complete execution. Which of these processes will finish LAST?

$$\begin{array}{|l|lll|lll|}\hline &\text{}  \rlap{\textbf{alloc}}  &&&\rlap{  \textbf{request}}  \\\hline  &\text{X} & \text{Y} & \text{Z}  &\text{X} & \text{Y} & \text{Z}  \\\hline  \textbf{P0} & \text{1} & \text{2} & \text{1}& \text{1} & \text{0} & \text{3}  \\\hline  \textbf{P1} & \text{2} & \text{0} & \text{1} & \text{0} & \text{1} & \text{2} \\\hline \textbf{P2} & \text{2} & \text{2} & \text{1} & \text{1} & \text{2} & \text{0} \\\hline \end{array}$$

  1. $P0$
  2. $P1$
  3. $P2$
  4. None of the above, since the system is in a deadlock

4 Answers

Best answer
41 41 votes

The answer is (C).

$$\overset{\text{Available Resources}}{\begin{array}{|l|l|l||}\hline
\text{X} & \text{Y} & \text{Z} \\\hline  \text{0} & \text{1} & \text{2}
\\\hline\end{array}}$$ Now, $P1$ will execute first, As it meets the needs. After completion, The available resources are updated.

$$\qquad  \overset{\text{Updated Available Resources}}{\begin{array}{|l|l|l||}\hline
\text{X} & \text{Y} & \text{Z} \\\hline  \text{2} & \text{1} & \text{3}
\\\hline\end{array}}$$
Now $P0$ will complete the execution, as it meets the needs.

After completion of $P0$ the table is updated and then $P2$ completes the execution.

Thus $P2$ completes the execution in the last.

• edited by
2 2 votes
Given:

🔹 Total Resources = [X Y Z] = [5 5 5]

🔹 Total Allocation = [X Y Z] = [5 4 3]

🔹 Available Resources = Total - Allocated

          = [5 5 5] - [5 4 3]

          = [0 1 2]

✅ Safe Sequence Check (Banker's Algorithm):

🔹 Step 1:

P1's request ≤ Available → [0 1 2] ≤ [0 1 2] → ✅

P1 executes → releases [2 0 1]

🔸 New Available = [0 1 2] + [2 0 1] = [2 1 3]

🔹 Step 2:

P0's request ≤ Available → [1 0 3] ≤ [2 1 3] → ✅

P0 executes → releases [1 2 1]

🔸 New Available = [2 1 3] + [1 2 1] = [3 3 4]

🔹 Step 3:

P2's request ≤ Available → [1 2 0] ≤ [3 3 4] → ✅

P2 executes → releases [2 2 1]

🔸 Final Available = [3 3 4] + [2 2 1] = [5 5 5]

✅ Conclusion:

🔸 Safe Sequence: P1 → P0 → P2

🔸 All processes can complete.

🔸 System is in a Safe State.

🔸 P2 executes last.
0 0 votes
Here there are two safe sequence possible

P1--> P0 -->P2 and P1-->P2-->P0 hence both option A and C are correct
1 flag:
✌ Edit necessary (Skyquake._)
Answer:
Position:
Show:

Related questions

28 28 votes
5 answers 5 answers
10.4k
10.4k views
go_editor asked Apr 23, 2016
10,427 views
A process, has been allocated $3$ page frames. Assume that none of the pages of the process are available in the memory initially. The process makes the following sequenc...
90 90 votes
14 answers 14 answers
47.8k
47.8k views
Kathleen asked Sep 21, 2014
47,754 views
Two processes, $P1$ and $P2$, need to access a critical section of code. Consider the following synchronization construct used by the processes:/* P1 */ while (true) { wa...
52 52 votes
4 answers 4 answers
26.1k
26.1k views
Kathleen asked Sep 21, 2014
26,124 views
A virtual memory system uses First In First Out (FIFO) page replacement policy and allocates a fixed number of frames to a process. Consider the following statements:P: I...
35 35 votes
6 answers 6 answers
13.8k
13.8k views
Kathleen asked Sep 21, 2014
13,769 views
An operating system used Shortest Remaining System Time first (SRT) process scheduling algorithm. Consider the arrival times and execution times for the following process...