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 containing IO::Async::Loop object. like, do it early, bestie, don't be late πŸ™ˆ
  • on_exit => CODE β€” a CODE reference for the on_exit event.
⚠️ heads up: once the on_exit continuation has been invoked, the IO::Async::PID object is removed from the containing IO::Async::Loop object. 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