Now, if the pressure of the gas is not everywhere the same, there is a net force which at each place acts towards lower pressure. This is because all the particles colliding with a piece of the fluid, or ``fluid element'' coming from the high-pressure side are depositing more energy in their direction of motion, than are the particles coming from the low-pressure side. This produces the net force called the ``pressure force''. If that is all there is, a fluid element which is at higher pressure than its surroundings will expand until the pressures are equalized, and the speed at which this occurs is the speed at which sound waves travel from one side to the other. For the Sun this is about five minutes.
Acting against the pressure forces is gravity. Each piece of fluid exerts gravity towards itself according to its mass, which is just its density times its volume. The total force on any piece is just the sum of the forces exerted by all the other elements, and this will be nonzero if there is more mass at a given distance on one side of the piece than on the other. Given a ball of gas, the force of gravity acts towards higher _density_ because there is more mass there. So. force balance is achieved by arranging the fluid in a sphere such that the gravity force acts inward towards the center, and the pressure force acts outward (I am ignoring rotation here). The system is a little more complicated for a star, since the interior temperature is not constant, and it depends on the past history of the fluid ensemble.
Let's derive de hydrostatic equilibrium; consider a cylindrical region (length dr, and area dA) at a distance r (from the center of the sun for example).
.
And the cylinder has properties:.
Density = .
Volume = .
Mass = dm = .
.
Now, what is the force of gravity acting on the cylinder?.
.
.
So now let's calculate the pressure acting on the cylinder. The cylinder feels the pressure from the stuff above it pushing down, plus the pressure from the stuff below pressing up.