The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

IO::Lambda::Signal - wait for pids and signals

DESCRIPTION

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.

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 an optional deadline/timeout, returns either the 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 the signal was caught, or undef on timeout. The corresponding lambda is new_signal :

   new_signal ($SIG, $TIMEOUT) :: () -> boolean
spawn (@LIST) -> ( output, $?, $!)

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 :

   new_process (@LIST) :: () -> ( output, $?, $!)

Lambda objects created by new_process have an additional field 'pid' initialized with the process pid value.

LIMITATION

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.

SEE ALSO

IO::Lambda, perlipc, IPC::Open2, IPC::Run

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.