NAME

Linux::Event::Fork::Child - Handle for a running child process

DESCRIPTION

A Linux::Event::Fork::Child object represents a child process that has started running.

It provides:

  • Access to metadata (pid, tag, data)

  • Streaming writes to child stdin

  • Signal delivery (kill)

  • Lifecycle tracking

Child objects are returned by:

$loop->fork(...)
$fork->fork(...)

when the child starts immediately.

If the process is queued instead of started, a Linux::Event::Fork::Request is returned.

EXECUTION MODEL

All methods on this object are called from the parent process.

The only code that runs in the child process is:

child => sub { ... }

Callbacks such as on_stdout, on_stderr, on_exit, and on_timeout run in the parent, inside the Linux::Event event loop.

METHODS

pid

my $pid = $child->pid;

Returns the process ID of the running child.

tag

my $tag = $child->tag;

Returns the tag associated with the fork request, if any.

data

my $data = $child->data;

Returns the arbitrary data payload associated with the request.

stdin_write

$child->stdin_write($bytes);

Writes bytes to the child's stdin.

Direction:

parent ---> child

This is nonblocking. Actual transmission occurs via the event loop.

If the child has already closed stdin, writes may fail or trigger an EPIPE event.

close_stdin

$child->close_stdin;

Closes the write end of the child's stdin.

After calling this, no further stdin writes are possible.

kill

$child->kill($signal);

Sends a signal to the child process.

Example:

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

is_running

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

Returns true if the child has not yet exited.

exit

my $exit = $child->exit;

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

Undefined until exit occurs.

LIFECYCLE

State progression:

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

After exit:

- stdout/stderr watchers are removed - stdin is closed - is_running returns 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.

  • After on_exit fires, the process is fully reaped.

AUTHOR

Joshua S. Day

LICENSE

Same terms as Perl itself.