Consider the following situation: a certain gas is contained in a well-insulated cylinder with a well-insulated piston head. Now, in this case the piston is not frictionless. In order for the piston head to move it needs to overcome a certain kinetic friction $F_k$.
Now let us consider that a certain mass $m$ is placed on top of the piston head and in the same time the piston head moves outwards a distance $h$. We also ignore the atmospheric pressure here.
The essence of the situation which I'm asking here through this particular example, is that there is friction involved, so there is dissipation of energy.
What we want to know here is the work performed by the gas during the expansion and the change on the internal energy of the whole system (the gas together with the cylinder and the piston).
To analyse that what I thought was to consider first that the mass $m$ provides a force downwards equal, in magnitude, to $F_g = mg$. It provides, thus, with a pressure of $P_g = mg/A$ where $A$ is the area of the piston head.
If the piston were frictionless we could use that $\mathrm dW = -P\,\mathrm dV$ so that here $W = -P \Delta V$ or using that $\Delta V = Ah$ we would have $W = -mgh$.
On the other hand, friction didn't enter here directly. My only guess was to consider the net force $F = F_k + mg$ and compute everything in the same way, just including the friction there. But this seems wrong. Another guess was to add to $W$ the work done by friction. In that case since it would oppose the piston, it would be $W = F_k h$, so that the total work would be $W = -mgh + F_k$, which is the same as in the first approach.
This seems terribly wrong. Also, since the energy related to friction is dissipated, it seems to me that $\Delta U$ for the whole system is the energy lost because of friction, but this doesn't seem to get out naturally of anything.
Probably the first law of thermodynamics is the way to go here, but I'm unsure.
Anyway, what is the correct way to deal with this kind of situation? How do we account for friction and dissipation in general, in practice?