IO::Async::PID(3pm)
π IO::Async::PID π
okay so bestie, welcome to IO::Async::PID β a User Contributed Perl Documentation classic, and honestly? it's giving "I just want to know when my child process dips out." β¨
This module lives in the IO::Async family and its whole entire job is: it fires a callback when a process exits. that's it. that's the girlboss moment. π
β¨ SYNOPSIS β¨
here's the vibe, copy-paste ready:
use IO::Async::PID;
use POSIX qw( WEXITSTATUS );
use IO::Async::Loop;
my $loop = IO::Async::Loop->new;
my $kid = $loop->fork(
code => sub {
print "Child sleeping..\n";
sleep 10;
print "Child exiting\n";
return 20;
},
);
print "Child process $kid started\n";
my $pid = IO::Async::PID->new(
pid => $kid,
on_exit => sub {
my ( $self, $exitcode ) = @_;
printf "Child process %d exited with status %d\n",
$self->pid, WEXITSTATUS($exitcode);
},
);
$loop->add( $pid );
$loop->run;
like... look at her go π¦ we fork a kid, we print, we watch, we get the callback. no cap.
πΈ DESCRIPTION πΈ
so IO::Async::PID is a subclass of IO::Async::Notifier, and what it does is invoke its callback when a process exits. that's the whole personality. it's a watcher. it's the friend who texts you "you home safe??" π«Ά
lowkey important note though: for most use cases, an IO::Async::Process object gives you way more control β setting up the process, connecting filehandles to it, sending data to it and receiving data from it. so if you need more than "tell me when it's gone", go look at that one instead. iykyk π
π« EVENTS π«
these events get invoked, and you can do it either with subclass methods or with CODE references in the parameters:
on_exit $exitcode
Invoked when the watched process exits. that's the moment. the finale. π
π PARAMETERS π
these named parameters can be passed to new or configure:
pid => INTβ the process ID to watch. must be given before the object has been added to the containingIO::Async::Loopobject. like, do it early, bestie, don't be late πon_exit => CODEβ aCODEreference for theon_exitevent.
β οΈ heads up: once theon_exitcontinuation has been invoked, theIO::Async::PIDobject is removed from the containingIO::Async::Loopobject. so it's a one-and-done situation. it served its purpose, it exited the group chat, iconic behavior honestly π
π METHODS π
pid
$process_id = $pid->pid;
Returns the underlying process ID. just hands you the number. simple. clean. slay. β
kill
$pid->kill( $signal );
Sends a signal to the process. yeah. you can just do that. π₯
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie!! π perl v5.40.1, dated 2026-02-21, IO::Async::PID(3pm) β go watch some processes exit, you absolute main character ππ
π¦ where this page comes from
- ubuntu stonking: libio-async-perl 0.805-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms