IO::Lambda::Signal - wait for pids and signals
The module provides access to the signal-based callbacks: generic signal listener signal, process ID listener pid, and the asynchronous version of system call, spawn.
signal
pid
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 an optional deadline/timeout, returns either the process' exit status, or undef on timeout. The corresponding lambda is new_pid :
new_pid
new_pid ($PID, $TIMEOUT) :: () -> $?|undef
Accepts signal name and optional deadline/timeout, returns 1 if the signal was caught, or undef on timeout. The corresponding lambda is new_signal :
undef
new_signal
new_signal ($SIG, $TIMEOUT) :: () -> boolean
Calls pipe open on @LIST, reads all data printed by the child process, and awaits for the process to finish. Returns three scalars - collected output, process exitcode $?, and an error string (usually $!). The corresponding lambda is new_process :
@LIST
$?
$!
new_process
new_process (@LIST) :: () -> ( output, $?, $!)
Lambda objects created by new_process have an additional field 'pid' initialized with the process pid value.
'pid'
pid and new_pid don't work on win32 because win32 doesn't use SIGCHLD/waitpid. Native implementation of spawn and new_process doesn't work for the same reason on win32 as well, therefore those were reimplemented using threads, and require a threaded perl.
IO::Lambda, perlipc, IPC::Open2, IPC::Run
Dmitry Karasik, <dmitry@karasik.eu.org>.
To install IO::Lambda, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IO::Lambda
CPAN shell
perl -MCPAN -e shell install IO::Lambda
For more information on module installation, please visit the detailed CPAN module installation guide.