| 1 |
NAME |
| 2 |
Sys::FreezeThaw - stop and start all user processes on a machine |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use Sys::FreezeThaw; |
| 6 |
|
| 7 |
Sys::FreezeThaw::freezethaw { |
| 8 |
# run code while system is frozen |
| 9 |
}; |
| 10 |
|
| 11 |
my $token = Sys::FreezeThaw::freeze; |
| 12 |
... do something ... |
| 13 |
Sys::FreezeThaw::thaw $token; |
| 14 |
|
| 15 |
DESCRIPTION |
| 16 |
Operating Systems current supported: Linux-2.6. |
| 17 |
|
| 18 |
This module implements a very specific feature: stopping(freezing and |
| 19 |
thawing/continuing all user processes on the machine. It works by |
| 20 |
sending SIGSTOP to all processes, parent-process first, so that the wait |
| 21 |
syscall will not trigger on stopped children. Restarting is done in |
| 22 |
reverse order. |
| 23 |
|
| 24 |
Using the combined function Sys::FreezeThaw::freezethaw is recommended |
| 25 |
as it will catch runtime errors, but stopping and restarting can be dine |
| 26 |
via seperate function calls. |
| 27 |
|
| 28 |
Sys::FreezeThaw::freezethaw { BLOCK } |
| 29 |
First tries to stop all processes. If successful, runs the given |
| 30 |
codeblock (or code reference), then restarts all processes again. As |
| 31 |
the system is basically frozen during the codeblock execution, it |
| 32 |
should be as fast as possible. |
| 33 |
|
| 34 |
Runtime errors will be caught with "eval". If an exception occurs it |
| 35 |
will be re-thrown after processes are restarted. If processes cannot |
| 36 |
be frozen or restarted, this function will throw an exception. |
| 37 |
|
| 38 |
Signal handlers for SIGPIPE, SIGHUP, SIGALRM, SIGUSR1 and SIGUSR2 |
| 39 |
will temporarily be installed, so if you want to catch these, you |
| 40 |
have to do so yourself within the executed codeblock. |
| 41 |
|
| 42 |
Try to do as few things as possible. For example, outputting text |
| 43 |
might cause a deadlock, as the terminal emulator on the other side |
| 44 |
of STDOUT might be stopped, etc. |
| 45 |
|
| 46 |
The return value of the codeblock is ignored right now, and the |
| 47 |
function doesn't yet return anything sensible. |
| 48 |
|
| 49 |
$token = Sys::FreezeThaw::freeze; |
| 50 |
Send SIGSTOP to all processes, and return a token that allows them |
| 51 |
to be thawed again. |
| 52 |
|
| 53 |
If an error occurs, an exception will be thrown and all stopped |
| 54 |
processes will automatically be thawed. |
| 55 |
|
| 56 |
Sys::FreezeThaw::thaw $token |
| 57 |
Take a token returned by Sys::FreezeThaw::freeze and send all |
| 58 |
processes a CONT signal, in the order required for them not to |
| 59 |
receive child STOP notifications. |
| 60 |
|
| 61 |
BUGS |
| 62 |
SIGCONT is not unnoticed by processes. Some programs (such as |
| 63 |
irssi-text) respond by flickering (IMHO a bug in irssi-text). Other |
| 64 |
programs might have other problems, but actual problems should be rare. |
| 65 |
However, one shouldn't overuse this module. |
| 66 |
|
| 67 |
AUTHOR |
| 68 |
Marc Lehmann <schmorp@schmorp.de> |
| 69 |
http://home.schmorp.de/ |
| 70 |
|