NAME

Linux::Event::Fork::Child - Handle for a running (or exited) child process

SYNOPSIS

my $child = $forker->spawn(
  cmd => [ ... ],
  stdin_pipe => 1,
  on_stdout => sub ($child, $chunk) { ... },
  on_exit   => sub ($child, $exit)  { ... },
);

$child->stdin_write("hello\n");
$child->close_stdin;

DESCRIPTION

A Child object represents a spawned child process whose stdout/stderr/stdin may be connected to the parent and integrated with the event loop.

Objects of this class are returned by "spawn" in Linux::Event::Fork when the child starts immediately.

METHODS

pid

my $pid = $child->pid;

Process ID.

loop

my $loop = $child->loop;

Returns the Linux::Event loop used to watch this child.

tag

my $tag = $child->tag;

Returns the tag provided to spawn (or undef).

data

my $data = $child->data;

Returns the data payload provided to spawn (or undef).

is_running

if ($child->is_running) { ... }

True until the child exit status has been observed.

exit

my $exit = $child->exit;

Returns a Linux::Event::Fork::Exit after the child has exited.

Returns undef until exit occurs.

kill($signal)

$child->kill('TERM');
$child->kill('KILL');

Sends a signal to the child process. Returns a boolean success value.

stdin_write($bytes)

$child->stdin_write($bytes);

Writes bytes to the child's stdin.

This only works if stdin was created (stdin or stdin_pipe was used).

If stdin_pipe was not enabled, stdin may be closed automatically after the initial stdin write.

close_stdin

$child->close_stdin;

Closes the child's stdin (immediately if no buffered bytes remain, otherwise once buffered bytes have been written).

LIFECYCLE

Typical progression:

created
    |
    +--> running
            |
            +--> exited
                    |
                    +--> on_exit callback fired

After exit:

  • stdout/stderr watchers are removed

  • stdin is closed

  • is_running becomes false

  • exit returns a valid Exit object

SAFETY NOTES

  • Do not call blocking operations inside callbacks.

  • Do not assume ordering between stdout and stderr.

  • Do not write to stdin after close_stdin.

AUTHOR

Joshua S. Day

LICENSE

Same terms as Perl itself.