Reaper(3)
π¦ Reaper(3) β the User Contributed Perl Documentation bestie you didn't know you needed π
okay so. this is the manual page for Reaper, and it lives in the User Contributed Perl Documentation section, section 3, and honestly? it's giving "underrated hero." let's get into it β¨
πΈ NAME πΈ
Reaper β support for reaping child processes via $SIG{CHLD}
like. it reaps. children. no cap. π«Ά
β¨ SYNOPSIS β¨
here's the vibe, look at this:
use Reaper qw( reaper reapPid pidStatus );
my $pid = fork;
if ( $pid == 0 ) { # child
exec $some_command;
}
reapPid ( $pid );
...
if ( defined(my $exit = pidStatus($pid)) ) {
# child exited, check the code...
}
iconic. gorgeous. register the pid, then later go check if it dipped and what it said on the way out. periodt π
π DESCRIPTION π
okay so here's the tea, bestie: perl has an annoying little problem with child processes. and like β technically it's not a perl-specific problem, it's just that with perl it's somewhat more difficult. the struggle is reaping child processes after they exit so they don't hang around as zombies forever, and doing it in a way that accurately captures the exit code of the child. zombie children? in this economy?? no thank you π
the right way to do it is to install a $SIG{CHLD} handler which calls waitpid to reap the child process and store $? at that point. clean. elegant. correct. but here's the problem β different modules may step on each other in installing their own version of the handler, and there's no uniform way of doing this. it's giving chaos. it's giving "everyone's yelling at once." π
for some situations, a local $SIG{CHLD} handler is sufficient, but often times the handler is no longer in scope at the time the child process exits β since the child may exit at any time. the local handler is dynamically scoped, not lexically, so it depends entirely on what subroutine is being executed at the time the signal is caught. like, the handler could be gone by then. gone gone. π
so the Reaper module provides a $SIG{CHLD} handler that can be installed globally as well as locally. it also supports chaining of signal handlers, meaning it will not just replace an existing $SIG{CHLD} handler β it plays nice, it shares, it's a good citizen π
it still requires applications to do the right thing in using this module and not installing their own versions. at least it provides a consistent implementation that can be shared between various modules. so like... cooperate, bestie. it's a group project. π
π₯ FUNCTIONS IN DETAIL π₯
reaper BLOCKβ install a local$SIG{CHLD}handler for a block of code, e.g.:
reaper {
do_something();
...
};
any children that exit while the block is being executed (whether started within that block or not) will cause the local $SIG{CHLD} to be executed. the child exit status will be saved, and will be available via the pidStatus() call. so it's not picky about who the parent is, it just handles business π
reapPid PIDLISTβ register one or more PIDs to be reaped. the reaper will only try to reap PIDs that have been registered, so that it does not steal the exit status for a pid from another handler. consent-first reaping, we love to see it πpidStatus PIDβ return the exit status of a specific PID. if no status for the PID is available (i.e. the process is still running), it returnsundef. soundef= "they're still out there living their life," basically π
π AUTHOR π
Jeremy Slade <jeremy@jkslade.net>
thank you for your service, king π«Ά
π POD ERRORS π
hey! the above document had some coding errors, which are explained below:
around line 55:
You can't have =items (as at line 151) unless the first thing after
the =over is an =item
not the pod being messy in public π the documentation itself has a lil formatting oopsie and honestly? relatable. we've all been there. moving on β¨
and that's the whole page, bestie! this one came to you via perl v5.42.0, dated 2025-07-25, and yes it really is titled Reaper(3) β go forth and reap responsibly ππ¦π
π¦ where this page comes from
- fedora 43: perl-Reaper 1.00-42.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms