| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Reflex::PID; |
|
2
|
|
|
|
|
|
|
# vim: ts=2 sw=2 noexpandtab |
|
3
|
|
|
|
|
|
|
$Reflex::PID::VERSION = '0.100'; |
|
4
|
1
|
|
|
1
|
|
7
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
|
|
extends 'Reflex::Base'; |
|
6
|
1
|
|
|
1
|
|
5091
|
use Reflex::Callbacks qw(make_emitter); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has pid => ( |
|
9
|
|
|
|
|
|
|
is => 'ro', |
|
10
|
|
|
|
|
|
|
isa => 'Int', |
|
11
|
|
|
|
|
|
|
required => 1, |
|
12
|
|
|
|
|
|
|
); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has active => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
isa => 'Bool', |
|
17
|
|
|
|
|
|
|
default => 1, |
|
18
|
|
|
|
|
|
|
); |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
with 'Reflex::Role::PidCatcher' => { |
|
21
|
|
|
|
|
|
|
att_pid => 'pid', |
|
22
|
|
|
|
|
|
|
att_active => 'active', |
|
23
|
|
|
|
|
|
|
cb_exit => make_emitter(on_exit => "exit"), |
|
24
|
|
|
|
|
|
|
method_start => 'start', |
|
25
|
|
|
|
|
|
|
method_stop => 'stop', |
|
26
|
|
|
|
|
|
|
method_pause => 'pause', |
|
27
|
|
|
|
|
|
|
method_resume => 'resume', |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
1; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
__END__ |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=pod |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=encoding UTF-8 |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=for :stopwords Rocco Caputo |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 NAME |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Reflex::PID - Watch the exit of a subprocess by its SIGCHLD signal. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 VERSION |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This document describes version 0.100, released on April 02, 2017. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Not a complete program. Please see the source for |
|
53
|
|
|
|
|
|
|
# Reflex::POE::Wheel::Run for one example. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Reflex::PID; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
watches pid_watcher => ( |
|
58
|
|
|
|
|
|
|
isa => 'Reflex::PID|Undef', |
|
59
|
|
|
|
|
|
|
role => 'process', |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub some_method { |
|
63
|
|
|
|
|
|
|
my $self = shift; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $pid = fork(); |
|
66
|
|
|
|
|
|
|
die $! unless defined $pid; |
|
67
|
|
|
|
|
|
|
exec("some-program.pl") unless $pid; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Parent here. |
|
70
|
|
|
|
|
|
|
$self->sigchild_watcher( |
|
71
|
|
|
|
|
|
|
Reflex::PID->new(pid => $pid) |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub on_process_exit { |
|
76
|
|
|
|
|
|
|
# Handle the event. |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Reflex::PID waits for a particular child process to exit. It emits a |
|
82
|
|
|
|
|
|
|
"signal" event with information about the child process when it has |
|
83
|
|
|
|
|
|
|
detected the child has exited. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Since Reflex::PID waits for a particular process ID, it's pretty much |
|
86
|
|
|
|
|
|
|
useless afterwards. Consider pairing it with Reflex::Collection if |
|
87
|
|
|
|
|
|
|
you have to maintain several transient processes. |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Reflex::PID extends Reflex::Signal to handle a particular kind of |
|
90
|
|
|
|
|
|
|
signal---SIGCHLD. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
TODO - However, first we need to make Reflex::PID objects stop |
|
93
|
|
|
|
|
|
|
themselves and emit "stopped" events when they're done. Otherwise |
|
94
|
|
|
|
|
|
|
Reflex::Collection won't know when to destroy them. |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 Public Events |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head3 exit |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Reflex::PID's "exit" event includes two named parameters. "pid" |
|
101
|
|
|
|
|
|
|
contains the process ID that exited. "exit" contains the process' |
|
102
|
|
|
|
|
|
|
exit value---a copy of C<$?> at the time the process exited. Please |
|
103
|
|
|
|
|
|
|
see L<perlvar/"$?"> for more information about that special Perl |
|
104
|
|
|
|
|
|
|
variable. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=over 4 |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L<Reflex|Reflex> |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L<Moose::Manual::Concepts> |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L<Reflex> |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L<Reflex::Signal> |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item * |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L<Reflex::POE::Wheel::Run> |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Reflex/ACKNOWLEDGEMENTS> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L<Reflex/ASSISTANCE> |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L<Reflex/AUTHORS> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L<Reflex/BUGS> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
L<Reflex/BUGS> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
L<Reflex/CONTRIBUTORS> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item * |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L<Reflex/COPYRIGHT> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<Reflex/LICENSE> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<Reflex/TODO> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=back |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
|
173
|
|
|
|
|
|
|
web interface at L<http://rt.cpan.org/Public/Dist/Display.html?Name=Reflex>. |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Rocco Caputo <rcaputo@cpan.org> |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Rocco Caputo. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
184
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 AVAILABILITY |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
The latest version of this module is available from the Comprehensive Perl |
|
189
|
|
|
|
|
|
|
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN |
|
190
|
|
|
|
|
|
|
site near you, or see L<https://metacpan.org/module/Reflex/>. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
|
195
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT |
|
196
|
|
|
|
|
|
|
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER |
|
197
|
|
|
|
|
|
|
PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, |
|
198
|
|
|
|
|
|
|
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
|
199
|
|
|
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
200
|
|
|
|
|
|
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
|
201
|
|
|
|
|
|
|
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME |
|
202
|
|
|
|
|
|
|
THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
|
205
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
|
206
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE |
|
207
|
|
|
|
|
|
|
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR |
|
208
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
|
209
|
|
|
|
|
|
|
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
|
210
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
|
211
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
|
212
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
|
213
|
|
|
|
|
|
|
DAMAGES. |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |