IO::Lambda::Signal(3)

πŸ“¦ version 1.34, in alpine 3.24

okay bestie, welcome to the IO::Lambda::Signal(3) page in User Contributed Perl Documentation πŸ’…βœ¨ this is the whole vibe, group-chat edition.

πŸ’– NAME πŸ’–

IO::Lambda::Signal β€” the module that is literally here to wait for pids and signals 🫢

🌸 DESCRIPTION 🌸

okay so this module provides access to the signal-based callbacks 😌✨ there are three main characters:

  • the generic signal listener, signal πŸŽ€
  • the process ID listener, pid πŸ¦‹
  • and the asynchronous version of the system call, spawn πŸ”₯

no cap, that's the whole lineup.

✨ SYNOPSIS ✨

bestie, here's the example code in all its glory πŸ‘‘

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 a PID and an optional deadline/timeout, then 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 a signal name and an 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 😭

🚨 no cap, this caveat matters: 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. periodt. πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

go check out these icons too: IO::Lambda, perlipc, IPC::Open2, IPC::Run 🌈

πŸ‘‘ AUTHOR πŸ‘‘

Dmitry Karasik, <dmitry@karasik.eu.org> πŸ’Œ

mwah πŸ’‹ that's the whole page β€” it's from perl v5.42.2, dated 2026-02-15, and it lives under IO::Lambda::Signal(3) πŸŽ€βœ¨

πŸ“¦ where this page comes from