NAME
IO::Lambda::Signal - wait for pids and signals
DESCRIPTION
The module provides access to signal-based callbacks, generic signal listener signal, process ID listener pid, and asynchronous version of system call, spawn.
SYNOPSIS
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;
USAGE
- pid ($PID, $TIMEOUT) -> $?|undef
-
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 - signal ($SIG, $TIMEOUT) -> boolean
-
Accepts signal name and optional deadline/timeout, returns 1 if signal was caught, or
undefon timeout. The corresponding lambda isnew_signal:new_signal ($SIG, $TIMEOUT) :: () -> boolean - spawn (@LIST) -> ( output, $?, $!)
-
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 isnew_process:new_process (@LIST) :: () -> ( output, $?, $!)Lambda created by
new_processhas field'pid'set to the process pid.
LIMITATIONS
spawn doesn't work on Win32, because pipes don't work with win32's select. They do (see Win32::Process) work with win32-specific WaitforMultipleObjects, which in turn IO::Lambda doesn't work with.
IPC::Run 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.
SEE ALSO
IO::Lambda, perlipc, IPC::Open2, IPC::Run, Win32::Process.
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.