Ubuntu is not sending SIGTERM on shutdown

Unfortunately, it does not quite work this way. Many of those programs that do actually have a signal handler, don't block the signal to show a confirmation dialog. Signal handling is often minimal or missing.

You can easily try it without having to shutdown. Just send SIGTERM to your running Firefox or LibreOffice process:

$ pkill firefox

Normally, Firefox might ask if you really want to close it. Also, it usually takes a while to close, especially when it's been running for a long time and using more than 1 GB of RAM - it often takes like a minute for the process to terminate after the its last window has been closed. None of this happens when you send SIGTERM, the process is just terminated instantly.

However, some desktop environments close all open windows before shutting down. Unlike SIGTERM, closing a window programmatically is like clicking on the X button of that window, or Alt + F4. This is also what the script in the other answer does - it uses wmctrl to close all open windows gracefully.

When a window is closed, the program is not in a rush and it can close everything within that window, for example open tabs, and it can also show a dialog window if there's unsaved work. Once all open windows of an application have been closed, the process usually terminates shortly after that.

So it depends on your desktop environment (assuming you use your desktop environment to shutdown and not sudo poweroff). For example, KDE should wait for open windows to be closed before shutting down, while MATE doesn't.

Bottom line: Close all open windows manually before shutting down. Or use a desktop environment that waits for all windows to be closed.

Tags:

Shutdown