Ok. I understand X session is a bit vague here so let me clarify what I mean by the phrase. I mean the situation where a person has been presented with a display manger screen ( eg xdm, kdm, gdm, mdm, lightDM ,,, ), "logs in", has finished using the computer, "logs out", the display manager screen is restored.
In the last step, processes that are not direct descendents of something like SSH or agetty should all go away.
I wish to place cleanup scripts between the "logs out" and the restoring of the display manager.
I need to know how X notifies other programs that the window manager is going down, and possibly how to pause the exit, if a program requires it.