Answer: 5
The need table suggests the future need.
Now the available resources in terms of $(A,B,C,D) = 0,0,1,1$
We can first satisfy $P3$ (b/c it needs $0,0,1,0$). Once $P3$ is satisfied it gives all the resources that it is currently allocated with, i.e. $1,1,2,1$. Thus, new available = $0,0,1,1 + 1,1,2,1 = 1,1,3,2$
With new available = $1,1,3,2$ we can satisfy $P1$ (b/c it needs $1,0,0,0$). Once $P1$ is satisfied it gives all the resources that it is currently allocated with, i.e. $2,1,1,1$. Thus, new available = $1,1,3,2 + 2,1,1,1 = 3,2,4,3.$
Now we to satisfy P2, P2 needs $0,2,X,2$. We can see that our available resources in $C = 4.$ So, with $4$ we can safely satisfy $P2$’s needs, and thus the system will be safe.
But the question asks
the smallest value of X for which the system will not be in safe state
This will happen only if X is such that it can’t be satisfied with our current available $C$ i.e $4$. Hence $X$ must be $5$.