Child(3pm)
π Child β bestie's guide to fork() without the tears π
ok so this is Child(3pm), straight out of the User Contributed Perl Documentation section, and honestly? it's a whole vibe. sit down, grab a strawberry drink, we're doing processes today π
β¨ NAME β¨
Child β an object oriented, simple interface to fork() π
πΈ DESCRIPTION πΈ
okay so real talk: fork() is lowkey a mess. it's too low level and it's genuinely hard to manage. the way that people just... forget to exit() at the end? forget to reap their children? forget to check exit status? π every single time. and the problem is literally the low level functions you're given to do those things. throw pipes for IPC on top of that and you've got a whole pile of stuff that nobody on this earth wants to think about, fr fr.
Child is an Object Oriented interface to fork. it gives you a clean way to start a child process, and manage it afterwards. it's giving: methods for running, waiting, killing, checking, and even communicating with a child process. iconic behavior only π
β οΈ NOTE: kill() is unpredictable on windows β strawberry perl sends the kill signal to the parent as well as the child. not a vibe. be careful out there bestie π
β SYNOPSIS β
π BASIC
use Child;
my $child = Child->new(sub {
my ( $parent ) = @_;
....
# exit() is called for you at the end.
});
my $proc = $child->start;
# Kill the child if it is not done
$proc->is_complete || $proc->kill(9);
$proc->wait; #blocking
π¦ IPC
# Build with IPC
my $child2 = Child->new(sub {
my $self = shift;
$self->say("message1");
$self->say("message2");
my $reply = $self->read(1);
}, pipe => 1 );
my $proc2 = $child2->start;
# Read (blocking)
my $message1 = $proc2->read();
my $message2 = $proc2->read();
$proc2->say("reply");
π SHORTCUT
Child can export the child() shortcut function when you ask for it. this function creates and starts the child process in one action. one step, no waiting, slay β¨
use Child qw/child/;
my $proc = child {
my $parent = shift;
...
};
you can also request IPC:
use Child qw/child/;
my $child = child {
my $parent = shift;
...
} pipe => 1;
π DETAILS π
first you define a child β you do this by constructing a Child object. and listen: defining a child does not start a new process. it's just the way to define what the new process will look like. think of it as the blueprint, not the build ποΈ
once you've defined the child, you can start the process by calling $child->start(). and here's the cute part β one child object can start as many processes as you like. infinite slay, no cap.
when you start a child, an Child::Link::Proc object is returned. this object provides multiple useful methods for interacting with your process. and within the process itself, an Child::Link::Parent is created and passed as the only parameter to the function you used to define the child. the parent object is how the child interacts with its parent π«Ά
π PROCESS MANAGEMENT METHODS π
@procs = Child->all_procs()β get a list of all the processes that have been started. heads up: this list is cleared in processes when they are started, that is, a child will not list its siblings. no snitching on the fam π@pids = Child->all_proc_pids()β get a list of all the pids of processes that have been started.Child->wait_all()β callwait()on all processes.
π§ EXPORTS π§
$proc = child( sub { ... } )$proc = child { ... }$proc = child( sub { ... }, $plugin, @data )$proc = child { ... } $plugin => @data
β create and start a process in one action. that's it, that's the whole job π
π CONSTRUCTOR π
$child = Child->new( sub { ... } )$child = Child->new( sub { ... }, $plugin, @plugin_data )
β create a new Child object. does not start the child. you gotta call start for that, bestie.
β¨ OBJECT METHODS β¨
$proc = $child->start()β start the child process. go go go π₯
πΈ SEE ALSO πΈ
Child::Link::Procβ the proc object that is returned by$child->start()Child::Link::Parentβ the parent object that is provided as the argument to the function used to define the child.Child::Link::IPCβ the base class for IPC plugin link objects. this provides the IPC methods.
π HISTORY π
most of this was part of Parallel::Runner, intended for use in the Fennec project. Fennec is being broken into multiple parts, and this is one such part. glow up era π±
π¦ FENNEC PROJECT π¦
this module is part of the Fennec project. see Fennec for more details. Fennec is a project to develop an extendable and powerful testing framework. together, the tools that make up the Fennec framework provide a potent testing environment πͺ
the tools provided by Fennec are also useful on their own. sometimes a tool created for Fennec is useful outside the greater framework, and such tools get turned into their own projects. this is one such project.
- Fennec - The core framework β the primary Fennec project that ties them all together.
β AUTHORS β
Chad Granum exodist7@gmail.com
π COPYRIGHT π
Copyright (C) 2010 Chad Granum
Child is free software; Standard perl licence.
Child is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.
okay that's the whole page bestie, go forth and fork responsibly π«Άπ
this was Child(3pm) as documented for perl v5.36.0, dated 2022-10-13 β periodt β¨π
π¦ where this page comes from
- ubuntu noble: libchild-perl 0.013-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libchild-perl 0.013-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libchild-perl 0.013-3 Β· 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