NAME
IO::Async::PID
- event callback on exit of a child process
SYNOPSIS
use IO::Async::PID;
use POSIX qw( WEXITSTATUS );
use IO::Async::Loop;
my $loop = IO::Async::Loop->new();
my $kid = $loop->detach_child(
code => sub {
print "Child sleeping..\n";
sleep 10;
print "Child exiting\n";
return 20;
},
);
print "Child process $kid started\n";
my $pid = IO::Async::PID->new(
pid => $kid,
on_exit => sub {
my ( $self, $exitcode ) = @_;
printf "Child process %d exited with status %d\n",
$self->pid, WEXITSTATUS($exitcode);
},
);
$loop->add( $pid );
$loop->loop_forever;
DESCRIPTION
This subclass of IO::Async::Notifier invokes its callback when a process exits.
This object may be used in one of two ways; as an instance with CODE references as callbacks, or as a base class with overridden methods.
- Subclassing
-
If a subclass is built, then it can override the following methods to handle events:
$self->on_exit( $exitcode )
PARAMETERS
The following named parameters may be passed to new
or configure
:
- pid => INT
-
The process ID to watch. Can only be given at construction time.
- on_exit => CODE
-
CODE reference to callback to invoke when the process exits. If not supplied, the subclass method will be called instead.
$on_exit->( $self, $exitcode )
Once the on_exit
continuation has been invoked, the IO::Async::PID
object is removed from the containing IO::Async::Loop
object.
METHODS
$process_id = $pid->pid
Returns the underlying process ID
$pid->kill( $signal )
Sends a signal to the process
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>