use IO::Async::PID; use POSIX qw( WEXITSTATUS ); use IO::Async::Loop; my $loop = IO::Async::Loop->new; my $kid = $loop->fork( 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->run;
For most use cases, a IO::Async::Process object provides more control of setting up the process, connecting filehandles to it, sending data to and receiving data from it.
Once the "on_exit" continuation has been invoked, the "IO::Async::PID" object is removed from the containing IO::Async::Loop object.
$process_id = $pid->pid
Returns the underlying process ID
$pid->kill( $signal )