I am beginning to suspect that Ubuntu is not telling the running applications that it is shutting down to let them quit correctly but instead forces them to quit.
If I leave chrome open when shutting down it says that it did not close correctly last time when I open it again after boot, LibreOffice does not ask me if I want to save my document and I am making an application which needs to run some code on exit but is not allowed to do so when the computer is shut down.
As I have understood it, SIGTERM is first sent to all processes to allow them to exit cleanly and if they don't exit SIGKILL is sent to force them to quit. It seems that Ubuntu is either not sending SIGTERM at all or does not give the applications enough time before sending SIGKILL.
Is there some way I can fix this?
I am running Ubuntu 16.04 but the problem existed in 15.10 as well. I can't tell if it was there before since I started using Ubuntu when 15.10 was the newest version.
Edit: I use Unity and shut down my computer by pressing the gear in the top right corner and selecting shut down, though the problem is the same if running sudo halt
in the terminal.
Edit: I am observing the same behavior when only logging out. My guess is that the signal is supposed to be sent on log out and therefore the problem arises on shutdown and log out.