Dissipation and first law of thermodynamics 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?
 A: Your question essentially comprises of two parts. Let's take them one by one:


*

*What is the workdone by the gas during expansion?
The approach is straightforward and you've already considered it. The total force that the gas has to overcome is $F_k + mg$. So if the gas expands by length $h$ work done by the system is $(F_k+mg)* h$ (assuming unit area of the cross-section). The dissipation doesn't come into the picture here. Because the gas doesn't care where it's energy is going. All it does is overcome the external pressure to expand.
Now move to second question:


*What is the change of internal energy of the whole system?
This is where dissipation comes in. Since the workdone due to dissipation is not stored in either system. So the change in internal energy of the whole(gas+piston) system is $\Delta U$ = -$F_k * h$.
A: If before putting the mass $m$ on the piston, in absence of external constraints, the piston is in equilibrium; since it is not mentioned in the problem description that gas has received some amount of heat; thus it is impossible that the piston moves upwards after putting the mass $m$ on it due to gas pressure. So, this question violates physics laws and we cannot explain it by physics.
Now, we should correct the question. So, consider two situations below:
$1$. At first, the mass $m$ has been placed on the piston and the piston is fixed by an external force (figure 1).

The external force is removed and the piston moves upwards a distance $h$ (figure 2).

$2$. At first, and in absence of external constraints, piston is in equilibrium (figure 3).

The mass $m$ is placed on the piston and the piston moves downwards a distance $h$ (figure 4).


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).

Since non-equilibrium processes are much complex and studying them need more and advanced informations, we assume that our processes are quasi-static processes. I.e. in the case $1$ removing the external force and in the case $2$ placing the mass $m$ is performed slowly and imperceptibly.
Analyzing of the case $1$:
We consider the gas in the cylinder as our system. Work done by the system (gas) is determined as $W=\int_{V_1}^{V_2}P\mathrm dV$ that $P$ is the pressure that resist against system’s boundary moving. If $F_k$ is constant during the process, then $P=\large{\frac{mg+F_k}A}$
$$\Longrightarrow \; W=\int_0^h\large{\frac{mg+F_k}A}A\mathrm dx=\left(mg+F_k\right)h=mgh+F_kh$$
From first law, we have: $\Delta U=-W=-\left(mg+F_k\right)h=-mgh-F_kh$
(because $Q=0$)
Decrease of the internal energy of the system (gas) is used for increasing the gravitational potential energy of the mass $m$ and also for increasing the internal energy of the surrounds (cylinder and piston) due to friction.
$$\left(\Delta U\right)_{whole}=\left(\Delta U\right)_{gas}+\left(\Delta U\right)_{surrounds}=-mgh-F_kh+F_kh=-mgh$$
Analyzing of the case $2$:
We consider the gas in the cylinder as our system. Work done by the system (gas) is determined as $W=\int_{V_1}^{V_2}P\mathrm dV$ that $P$ is the pressure that resist against system boundary moving (in a quasi-static process, $P$ is the system pressure at each moment). Since $P$ is a positive quantity and $V_1\gt V_2$, thus work done by the system (gas) is negative. I.e. the surrounds has done work on the system.
$$\Longrightarrow \; W=\int_{V_1}^{V_2}P\mathrm dV=-X \quad ; X\gt 0$$
From first law, we have: $\Delta U=-W=X$
Decrease of the gravitational potential energy of the mass $m$ is used for increasing the internal energy of the system (gas) and also for increasing the internal energy of the surrounds (cylinder and piston) due to friction.
$$\Longrightarrow \; mgh=\Delta U+F_kh$$
$$\Longrightarrow \; W=-mgh+F_kh$$
$$\left(\Delta U\right)_{whole}=\left(\Delta U\right)_{gas}+\left(\Delta U\right)_{surrounds}=mgh-F_kh+F_kh=mgh$$
A: 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).
Consider the gas, piston and cylinder together as constituting the system. Consider the piston to be massless. Consider the mass, $m$,  on top of the piston to constitute the surroundings (you indicated atmospheric pressure is to be ignored).
Given these assumptions, the work done by the system on the surroundings is $mgh$. But the gas (the only part of the system that does work) also does friction work. So the total work done by the gas is:
$$W_{gas}=mgh + W_{friction}$$
The first law is (for a closed system):
$$\Delta U=Q-W$$
Where $Q$ is the heat transferred between the system and surroundings (considered positive if transferred to the system) and $W$ is the work transfer between the system and the surroundings (considered positive if work is done by the system on the surroundings).  
Since you indicated the cylinder and piston are perfectly thermally insulated, $Q=0$ and
$$\Delta U=-W$$
The key point here is that the work, $W$ , in this equation is only the work that crosses the boundary between the system and the surroundings.  That work is $mgh$. The friction work does not cross the boundary. This part of the work raises the interior temperature of the face of the piston cylinder walls above that of the interior gas. This results in heat transfer from the cylinder and piston surfaces to the gas, increasing the internal energy of the gas.
This seems terribly wrong. Also, since the energy related to friction is dissipated, it seems to me that $\Delta U$ or the whole system is the energy lost because of friction, but this doesn't seem to get out naturally of anything.
The friction work is not energy lost. It is retained by the system. What is lost (due to the process being irreversible) is the potential for the gas doing more work on the surroundings. 
Bottom line, part of the work done by the gas (friction work) is retained as internal energy and part  of the work that crosses the boundary (work done raising the weight) reduces the internal energy. 
Hope this helps.
