IO::Lambda::Signal - wait for pids and signals
The module provides access to signal-based callbacks, generic signal listener
signal, process ID listener pid, and asynchronous version of system
call, spawn.
use strict; use IO::Lambda qw(:all); use IO::Lambda::Signal qw(pid spawn);
# pid my $pid = fork; exec "/bin/ls" unless $pid; lambda { context $pid, 5; pid { my $ret = shift; print defined($ret) ? ("exitcode(", $ret>>8, ")\n") : "timeout\n"; } }-> wait;
# spawn this lambda { context "perl -v"; spawn { my ( $buf, $exitcode, $error) = @_; print "buf=[$buf], exitcode=$exitcode, error=$error\n"; } }-> wait;
Accepts PID and optional deadline/timeout, returns either process exit status,
or undef on timeout. The corresponding lambda is new_pid :
new_pid ($PID, $TIMEOUT) :: () -> $?|undef
Accepts signal name and optional deadline/timeout, returns 1 if signal was caught,
or undef on timeout. The corresponding lambda is new_signal :
new_signal ($SIG, $TIMEOUT) :: () -> boolean
Calls pipe open on @LIST, read all data printed by the child process,
and waits for the process to finish. Returns three scalars - collected output,
process exitcode $?, and an error string (usually $!). The corresponding
lambda is new_process :
new_process (@LIST) :: () -> ( output, $?, $!)
Lambda created by new_process has field 'pid' set to the process pid.
spawn doesn't work on Win32, because pipes don't work with win32's select.
They do (see the Win32::Process manpage) work with win32-specific
WaitforMultipleObjects, which in turn IO::Lambda doesn't work with.
the IPC::Run manpage apparently manages to work on win32 and be compatible with
select. I don't think that dragging IPC::Run as a dependency here
worth it, but if you need it, send me a working example so I can at least include
it here.
the IO::Lambda manpage, the perlipc manpage, the IPC::Open2 manpage, the IPC::Run manpage, the Win32::Process manpage.
Dmitry Karasik, <dmitry@karasik.eu.org>.