Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
(perl) Object oriented simple interface to fork()
Perl Perl6
tree: 0b9dd555b9

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


    Child - Object oriented simple interfare to fork()

    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 IPC and you just have a pile of things nobody wants to think about.

    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.

        use Child;

        my $child = Child->new(sub {
            my $self = shift;
            # exit() is called for you at the end.

        # Build with IPC
        my $child2 = Child->new(sub {
            my $self = shift;
            my $reply = $self->read(1);
        }, pipe => 1 );

        # Read (blocking)
        my $message1 = $child2->read(1);

        # Read (non-blocking)
        my $message2 = $child2->read();


        # Kill the child if it is not done
        $child->complete || $child->kill(9);

        $child->wait; #blocking

    Child can export the child(&) shortcut function when requested. This
    function creates and starts the child process.

        use Child qw/child/;

        my $child = child {
            my $self = shift;

    To add IPC to children created with child(), import with ':pipe'. How
    child() behaves regarding IPC is lexical to each importing class.

        use Child qw/child :pipe/;

        my $child = child {
            my $self = shift;

        my $message1 = $child->read(1);

    $class->new( sub { ... } )
    $class->new( sub { ... }, pipe => 1 )
        Create a new Child object. Does not start the child.

        Start the child process.

    $bool = $child->is_complete()
        Check if the child is finished (non-blocking)

        Wait on the child (blocking)

        Send the $SIG signal to the child process.

        Read a message from the child. Takes a single boolean argument; when
        true the method blocks.

    $child->write( @MESSAGES )
        Send the messages to the child. works like print, you must add "\n".

    $child->say( @MESSAGES )
        Send the messages to the child. works like say, adds the seperator
        for you (usually "\n").

        Returns the child PID (only in parent process).

        If the child has exited this will contain the status. NOTE: You must
        call wait or is_complete before this field is populated.

        Returns the coderef used to construct the Child.

        Returns the parent processes PID. (Only in child)

    Most of this was part of Parrallel::Runner intended for use in the
    Fennec project. Fennec is being brocken into multiple parts, this is one
    such part.

    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 greator framework. Such
    tools are turned into their own projects. This is one such project.

    Fennec - The core framework
      The primary Fennec project that ties them all together.

    Chad Granum

    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.

Something went wrong with that request. Please try again.