Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
In my case it is gnome-session-save, and with the --logout option it does exactly what I was looking for. Thank you. –  Elena Jul 10 '12 at 12:22
add comment

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.

share|improve this answer
    
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. –  Elena Jul 10 '12 at 12:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.