1IO::Async::PID(3)     User Contributed Perl Documentation    IO::Async::PID(3)
2
3
4

NAME

6       "IO::Async::PID" - event callback on exit of a child process
7

SYNOPSIS

9          use IO::Async::PID;
10          use POSIX qw( WEXITSTATUS );
11
12          use IO::Async::Loop;
13          my $loop = IO::Async::Loop->new;
14
15          my $kid = $loop->fork(
16             code => sub {
17                print "Child sleeping..\n";
18                sleep 10;
19                print "Child exiting\n";
20                return 20;
21             },
22          );
23
24          print "Child process $kid started\n";
25
26          my $pid = IO::Async::PID->new(
27             pid => $kid,
28
29             on_exit => sub {
30                my ( $self, $exitcode ) = @_;
31                printf "Child process %d exited with status %d\n",
32                   $self->pid, WEXITSTATUS($exitcode);
33             },
34          );
35
36          $loop->add( $pid );
37
38          $loop->run;
39

DESCRIPTION

41       This subclass of IO::Async::Notifier invokes its callback when a
42       process exits.
43
44       For most use cases, a IO::Async::Process object provides more control
45       of setting up the process, connecting filehandles to it, sending data
46       to and receiving data from it.
47

EVENTS

49       The following events are invoked, either using subclass methods or CODE
50       references in parameters:
51
52   on_exit $exitcode
53       Invoked when the watched process exits.
54

PARAMETERS

56       The following named parameters may be passed to "new" or "configure":
57
58   pid => INT
59       The process ID to watch. Must be given before the object has been added
60       to the containing IO::Async::Loop object.
61
62   on_exit => CODE
63       CODE reference for the "on_exit" event.
64
65       Once the "on_exit" continuation has been invoked, the "IO::Async::PID"
66       object is removed from the containing IO::Async::Loop object.
67

METHODS

69   pid
70          $process_id = $pid->pid
71
72       Returns the underlying process ID
73
74   kill
75          $pid->kill( $signal )
76
77       Sends a signal to the process
78

AUTHOR

80       Paul Evans <leonerd@leonerd.org.uk>
81
82
83
84perl v5.34.0                      2022-01-21                 IO::Async::PID(3)
Impressum