How can I hibernate a running application?
You can use the killall
command to send a SIGSTOP
signal to all processes matching a given name to freeze them and later send SIGCONT
the same way to thaw them again.
First find out the process name using pgrep -l SEARCH_PATTERN
:
$ pgrep -l chrom
13010 chromium-browse
13036 chromium-browse
13038 chromium-browse
13153 chromium-browse
13166 chromium-browse
13169 chromium-browse
13175 chromium-browse
13187 chromium-browse
13195 chromium-browse
13206 chromium-browse
Note that it will trim long names, therefore the r
is missing. But this isn't a problem as you can use Tab completion to enter the process name which will complete it automatically.
Then you send the SIGSTOP
signal to all processes named chromium-browser
like this:
$ killall -s STOP chromium-browser
The Chromium window will grey out as if it became unresponsive. Well, it really became unresponsive, so that was to be expected. You can't interact with the window in any way now (except for the menu bar and minimizing etc. which is handled by the window manager and not the application itself). But the events from clicking buttons etc. are still generated and added to the application's event queue, so they will all be processed at once when you thaw the application again!
You thaw the application again by simply running this command that sends the SIGCONT
signal to the specified processes:
$ killall -s CONT chromium-browser
Sometimes freezing an application this way can cause it to crash, so make sure important stuff is saved before freezing an application.
In rare cases even the desktop environment/window manger/whatever else might become unresponsive as well. In this case you have to thaw the frozen application through a TTY:
Press Ctrl+Alt+F1 to switch to TTY1. You will be asked to log in, so enter your username and password. Then run the command to thaw the application the same way you would run it through your normal terminal emulator. After that switch back to the desktop (TTY7) using Ctrl+Alt+F7 and you should be fine again.
To suspend, try:
killall -SIGTSTP chromium-browser
If this does not work, try the forceful version: killall -SIGSTOP chromium-browser
.
Either way, to continue use killall -SIGCONT chromium-browser
. I tried with Firefox and it worked. Do note however, that if you click buttons in Chromium while it is suspended it will execute that stuff once you continue it's execution.
You can try the following (in a Terminal):
ps aux | grep gedit
Then you'll see something like this:
barend 7166 5.3 1.0 722620 39044 ? Sl 16:19 0:00 gedit
Write down the number 7166 (or whatever number it is) and then do:
kill -STOP 7166
That will suspend execution of the process. It won't immediately free the memory used by it, but the memory will be available for other processes if they need it.
Then do
kill -CONT 7166
to work with the program again.
Note that you have to change 7166 where appropriate.