IPC::Signal::Force - force default handling of a signal
use IPC::Signal::Force qw(force_raise); force_raise "TERM";
This module exports one function,
force_raise, which invokes a default signal handler regardless of the signal's current handling.
SIGNAL must be the name of a signal (e.g., "TERM"). The specified signal is delivered to the current process, with the handler for the signal temporarily reset to the default. The signal is also temporarily unblocked if it was initially blocked. The overall effect is to synchronously invoke the default handler for the signal, regardless of how the signal would be handled the rest of the time.
This is mainly useful in a handler for the same signal, if the handler wants to do something itself and also call the default handler. For example, a handler for SIGTERM might shut down the program neatly and then
force_raise("TERM"), which achieves a graceful shutdown while also letting the parent process see that the process terminated due to a signal rather than by
A similar, but slightly more complex, case is a handler for SIGTSTP (tty-initiated stop), which in a curses-style program might need to restore sane tty settings,
force_raise("TSTP"), and then (after the process has been restarted) reassert control of the tty and redraw the screen.
If the signal in question is delivered from somewhere else while
force_raise is executing, there is a race condition that makes it is possible for the default signal handler to be called more than once. There appears to be no way to avoid this in POSIX.
Andrew Main (Zefram) <email@example.com>
Copyright (C) 2004, 2007, 2010 Andrew Main (Zefram) <firstname.lastname@example.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.