My Textbook says that:
Reflection of sound waves for displacement from a rigid boundary (e.g. closed end of an organ pipe) is analogous to reflection of a string wave from rigid boundary; reflection accompanied by an inversion i.e. an abrupt phase change of $\pi$. This is consistent with the requirement of displacement amplitude to remain zero at the rigid end, since a medium particle at the rigid end can not vibrate. As the excess pressure and displacement corresponding to the same sound wave vary by $\pi/2$ in term of phase, a displacement minima at the rigid end will be a point of pressure maxima. This implies that the reflected pressure wave from the rigid boundary will have same phase as the incident wave, i.e., a compression pulse is reflected as a compression pulse and a rarefaction pulse is reflected as a rarefaction pulse.
I did not understand the last statement. If the phase change after reflection from a rigid boundary is $\pi$, then shouldn't a rarefaction pulse be reflected as a compression pulse and a compression pulse as a rarefaction pulse, afterall the phase difference between a particle at rarefaction and compression is $\pi$. Where am I wrong? I think I have trouble understand the $\pi$ phase change in the case of sound wave. The same thing was easy to understand in the case of wave on a string. Please clear this confusion!