View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Mark Nunberg > POE-Component-ProcTerminator-0.03 > POE::Component::ProcTerminator



Annotate this POD

View/Report Bugs
Module Version: 0.03   Source  


POE::Component::ProcTerminator - Safely and easily kill runaway processes


This is a POE component wrapping the functionality of Proc::Terminator, but using POE's timers and event loop instead of the built-in (and obviously blocking) sleep-based loop.


Set up the component..

    POE::Component::ProcTerminator->spawn(Alias => "proc_terminator");

Later, in your code..

    $_[KERNEL]->call(proc_terminator =>
                    terminate =>
                        siglist => [ SIGINT, SIGTERM, SIGKILL ]

And that's all!


Semantics here are identical to that specified in Proc::Terminator. This manpage describes feature specific to the POE component

spawn(Alias => "a name", %options..)

If the Alias parameter is missing, then it will spawn the default session, called proc_terminator

Further options are taken as defaults to be used for subsequent calls to "terminate"

$kernel->post($alias, terminate => $pid, { other => options })

Instruct the component to begin trying to kill $pid, where $pid can either be a single PID, or an array reference of PIDs.

The second argument may be an optional hashref of options, accepting the same kinds of things that Proc::Terminator's proc_terminate does.

The more relevant options are


A list of signals which will be used to kill off the process. Signals are tried in succession, until the process is either dead or there are no more signals left in the list. The defaults exist in @Proc::Terminator::DefaultSignalOrder


An interval (in seconds) to wait between shifting the signal list (specified in siglist). In the world of POE, this effectively means how often the timer event will be called.

Some additional options:


If for whatever reason Proc::Terminator is unable to kill your process, this callback will be invoked with a Proc::Terminator::Batch as its sole argument. See Proc::Terminator for documentation on that object.


Control the behavior of POE::Component::ProcTerminator when the session terminates prematurely (e.g. the kernel is being shut down, or some other exceptional terminal condition has occured).

The default behavior is to not do anything.

This value is one or more of the following flags, OR'd together (these are sub constants, exported to your namespace).


This instructs the cleanup handler to block and loop for this batch, as Proc::Terminator does in the synchronous API. The maximum time each batch can block is 5 seconds (though this might be configurable).


If SIGKILL was not in the original list of signals to send to the process, then push it to the end of the signal-to-send stack. This only makes sense with the PROCTERMf_CLEANUP_BLOCK


Blindly sends a SIGKILL to the remaining processes. It does not make sense to use this flag with the other flags.


When POE shuts down and the component is about to stop, it will call an iteration of the loop (hopefully killing it). In the future I might want to do something like either invoke a 'real' Proc::Terminate session (with a reasonable time limit) or nuke them all with SIGKILL. Dunno?




Copyright (C) 2012 M. Nunberg

You may use and distribute this software under the same terms and conditions as Perl itself.

syntax highlighting: