11

I've configured the Debian system on my netbook to shut down whenever the battery runs too low. Problem is, shutting down kills all running applications without giving them any chance to save any document I may be working on.

I'd like to write a script to "gently" close all open applications before shutdown kicks in, but I can't find a way to broadcast a "Close" message to all running applications in Gnome. Is there a way?

Thanks.

EDIT: Hibernating does not work on my netbook, so I can't use it as an alternative solution.

2 Answers 2

7

The shutdown will gently "close" (SIGTERM) all open applications, giving the opportunity to terminate gracefully. Then, after a time, if the process does not respond, a hard kill (SIGKILL) - not giving time to close files or, more importantly, databases.

A shutdown is an autonomous procedure. It is not expected to respond to user input. So it would not allow for giving a user the option to save beforehand. This is the reason why both emacs and vi(m) have recovery files. Check with your applications if there is an auto-save feature. For the most part, the old adage "Save early, save often" goes.

Have you thought to change the power settings to have the system hibernate? This will save the state of the system (including running programs) for the next start.

1
  • That there two phases - SIGTERM followed by SIGKILL - during the shutdown makes sense, for I hear a beep a few seconds before the system shutdowns. I will look for ways to make applications deal with that in a desired manner. Hibernate does not work on my netbook, otherwise it would be the perfect solution. Thank you.
    – Eleno
    Jul 10, 2012 at 12:13
3

You could ask gnome to close the current session before the shutdown. Something like:

gnome-session-quit --logout --no-prompt
shutdown -h now

The command syntax can change according to gnome version (e.g. gnome-session-quit is the new name of gnome-session-save).

The --no-prompt force running applications to quit without user confirmation.

1
  • In my case it is gnome-session-save, and with the --logout option it does exactly what I was looking for. Thank you.
    – Eleno
    Jul 10, 2012 at 12:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .