.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Child 3pm" .TH Child 3pm "2022-10-13" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Child \- Object oriented simple interface to fork() .SH "DESCRIPTION" .IX Header "DESCRIPTION" Fork is too low level, and difficult to manage. Often people forget to exit at the end, reap their children, and check exit status. The problem is the low level functions provided to do these things. Throw in pipes for \s-1IPC\s0 and you just have a pile of things nobody wants to think about. .PP Child is an Object Oriented interface to fork. It provides a clean way to start a child process, and manage it afterwords. It provides methods for running, waiting, killing, checking, and even communicating with a child process. .PP \&\fB\s-1NOTE\s0\fR: \fBkill()\fR is unpredictable on windows, strawberry perl sends the kill signal to the parent as well as the child. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .SS "\s-1BASIC\s0" .IX Subsection "BASIC" .Vb 1 \& 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 .Ve .SS "\s-1IPC\s0" .IX Subsection "IPC" .Vb 8 \& # 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"); .Ve .SS "\s-1SHORTCUT\s0" .IX Subsection "SHORTCUT" Child can export the \fBchild()\fR shortcut function when requested. This function creates and starts the child process in one action. .PP .Vb 1 \& use Child qw/child/; \& \& my $proc = child { \& my $parent = shift; \& ... \& }; .Ve .PP You can also request \s-1IPC:\s0 .PP .Vb 1 \& use Child qw/child/; \& \& my $child = child { \& my $parent = shift; \& ... \& } pipe => 1; .Ve .SH "DETAILS" .IX Header "DETAILS" First you define a child, you do this by constructing a Child object. Defining a child does not start a new process, it is just the way to define what the new process will look like. Once you have defined the child you can start the process by calling \f(CW$child\fR\->\fBstart()\fR. One child object can start as many processes as you like. .PP When you start a child an Child::Link::Proc object is returned. This object provides multiple useful methods for interacting with your process. Within the process itself an Child::Link::Parent is created and passed as the only parameter to the function used to define the child. The parent object is how the child interacts with its parent. .SH "PROCESS MANAGEMENT METHODS" .IX Header "PROCESS MANAGEMENT METHODS" .ie n .IP "@procs = Child\->\fBall_procs()\fR" 4 .el .IP "\f(CW@procs\fR = Child\->\fBall_procs()\fR" 4 .IX Item "@procs = Child->all_procs()" Get a list of all the processes that have been started. This list is cleared in processes when they are started; that is a child will not list its siblings. .ie n .IP "@pids = Child\->\fBall_proc_pids()\fR" 4 .el .IP "\f(CW@pids\fR = Child\->\fBall_proc_pids()\fR" 4 .IX Item "@pids = Child->all_proc_pids()" Get a list of all the pids of processes that have been started. .IP "Child\->\fBwait_all()\fR" 4 .IX Item "Child->wait_all()" Call \fBwait()\fR on all processes. .SH "EXPORTS" .IX Header "EXPORTS" .ie n .IP "$proc = child( sub { ... } )" 4 .el .IP "\f(CW$proc\fR = child( sub { ... } )" 4 .IX Item "$proc = child( sub { ... } )" .PD 0 .ie n .IP "$proc = child { ... }" 4 .el .IP "\f(CW$proc\fR = child { ... }" 4 .IX Item "$proc = child { ... }" .ie n .IP "$proc = child( sub { ... }, $plugin, @data )" 4 .el .IP "\f(CW$proc\fR = child( sub { ... }, \f(CW$plugin\fR, \f(CW@data\fR )" 4 .IX Item "$proc = child( sub { ... }, $plugin, @data )" .ie n .IP "$proc = child { ... } $plugin => @data" 4 .el .IP "\f(CW$proc\fR = child { ... } \f(CW$plugin\fR => \f(CW@data\fR" 4 .IX Item "$proc = child { ... } $plugin => @data" .PD Create and start a process in one action. .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .ie n .IP "$child = Child\->new( sub { ... } )" 4 .el .IP "\f(CW$child\fR = Child\->new( sub { ... } )" 4 .IX Item "$child = Child->new( sub { ... } )" .PD 0 .ie n .IP "$child = Child\->new( sub { ... }, $plugin, @plugin_data )" 4 .el .IP "\f(CW$child\fR = Child\->new( sub { ... }, \f(CW$plugin\fR, \f(CW@plugin_data\fR )" 4 .IX Item "$child = Child->new( sub { ... }, $plugin, @plugin_data )" .PD Create a new Child object. Does not start the child. .SH "OBJECT METHODS" .IX Header "OBJECT METHODS" .ie n .IP "$proc = $child\->\fBstart()\fR" 4 .el .IP "\f(CW$proc\fR = \f(CW$child\fR\->\fBstart()\fR" 4 .IX Item "$proc = $child->start()" Start the child process. .SH "SEE ALSO" .IX Header "SEE ALSO" .IP "Child::Link::Proc" 4 .IX Item "Child::Link::Proc" The proc object that is returned by \f(CW$child\fR\->\fBstart()\fR .IP "Child::Link::Parent" 4 .IX Item "Child::Link::Parent" The parent object that is provided as the argument to the function used to define the child. .IP "Child::Link::IPC" 4 .IX Item "Child::Link::IPC" The base class for \s-1IPC\s0 plugin link objects. This provides the \s-1IPC\s0 methods. .SH "HISTORY" .IX Header "HISTORY" Most of this was part of Parallel::Runner intended for use in the Fennec project. Fennec is being broken into multiple parts, this is one such part. .SH "FENNEC PROJECT" .IX Header "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. .PP The tools provided by Fennec are also useful on their own. Sometimes a tool created for Fennec is useful outside the greater framework. Such tools are turned into their own projects. This is one such project. .IP "Fennec \- The core framework" 2 .IX Item "Fennec - The core framework" The primary Fennec project that ties them all together. .SH "AUTHORS" .IX Header "AUTHORS" Chad Granum exodist7@gmail.com .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2010 Chad Granum .PP Child is free software; Standard perl licence. .PP Child is distributed in the hope that it will be useful, but \s-1WITHOUT ANY WARRANTY\s0; without even the implied warranty of \s-1MERCHANTABILITY\s0 or \s-1FITNESS FOR A PARTICULAR PURPOSE.\s0 See the license for more details.