lib/Mojo/IOLoop/ReadWriteProcess/Session.pm

filter: Statementstmt 93.9% 125 / 133 Branchbran 48.4% 32 / 66 Conditioncond 50.0% 10 / 20 MC/DCmcdc 16.6% 2 / 12 Subroutinesub 100% 41 / 41 Podpod 88.8% 16 / 18 totaltotal 77.9% 226 / 290 CC 44 SCAR 36.7
CC
44
Cov
76%
_get_prctl_syscall
162.8
_prctl
9.5
clean
5.9
CRAP 39.2
« lib/Mojo/IOLoop/ReadWriteProcess.pm ↑ Summary lib/Mojo/IOLoop/ReadWriteProcess/Namespace.pm »
1 package Mojo::IOLoop::ReadWriteProcess::Session;
2  
3 39 ▶use Mojo::Base 'Mojo::EventEmitter';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 39 ▶use Mojo::IOLoop::ReadWriteProcess;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 39 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 39 ▶use POSIX qw( :sys_wait_h :signal_h );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 39 ▶use Mojo::Collection 'c';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 39 our @EXPORT_OK = qw(session);
10 39 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 39 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 39 ▶use constant DEBUG => $ENV{MOJO_PROCESS_DEBUG};
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # See https://github.com/torvalds/linux/blob/master/include/uapi/linux/prctl.h
17 39 ▶use constant PR_SET_CHILD_SUBREAPER => 36;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 39 ▶use constant PR_GET_CHILD_SUBREAPER => 37;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 39 has subreaper => 0;
21 39 has collect_status => 1;
22 13 ▶has orphans => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
23 31 ▶has process_table => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
24 33 ▶has collected_info => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
25 39 has 'handler';
26 39 has emit_from_sigchld => 1;
27  
28 39 my $singleton;
29  
30 428 ▶sub new { $singleton ||= __PACKAGE__->SUPER::new }
Subroutine new: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$singleton ||= __PACKAGE__->SUPER::new
l!l&&r!l&&!r
394340
MC/DC0%0/2
$singleton ||= __PACKAGE__->SUPER::new
$singleton __PACKAGE__->SUPER::new
Truth table66%2/3
A ||= B
A= $singletonB= __PACKAGE__->SUPER::new
ABresult
1X1
011
000
31  
32 1 ▶sub disable {
Subroutine disable: called CC=1 SCAR=0.0
Pod documented
33 1 ▶ $singleton->_protect(sub { $SIG{CHLD} = $singleton->handler() });
Subroutine __ANON__: called CC=1 SCAR=0.0
34 }
35  
36 1277 ▶sub _protect {
Subroutine _protect: called CC=4 SCAR=13.9
37 1277 ▶ shift if $_[0] && $_[0] eq $singleton;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] and $_[0] eq $singleton 1275 2 1277
Condition66%2/3
$_[0] and $_[0] eq $singleton
!ll&&!rl&&r
021275
MC/DC50%1/2
$_[0] and $_[0] eq $singleton
$_[0] $_[0] eq $singleton
Truth table66%2/3
A and B
A= $_[0]B= $_[0] eq $singleton
ABresult
0X0
100
111
38 1277 ▶ my ($sig, $cb) = (@_ > 1 ? pop : SIGCHLD, pop);
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 3 1274 1277
39 1277 my ($sigset, $blockset) = (POSIX::SigSet->new, POSIX::SigSet->new($sig));
40 1277 $singleton->emit(protect => [$cb, $sig]);
41 1277 sigprocmask(SIG_BLOCK, $blockset, $sigset);
42 1277 my $r = $cb->();
43 1277 sigprocmask(SIG_SETMASK, $sigset);
44 1277 return $r;
45 }
46  
47 276 ▶sub enable {
Subroutine enable: called CC=2 SCAR=6.9
Pod documented
48 276 ▶ return if $singleton->handler();
Branch: 1 branch
BranchTrueFalseTotal
if $singleton->handler 191 85 276
49 85 $singleton->handler($SIG{CHLD});
50 $singleton->_protect(
51 85 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 288 ▶ $SIG{CHLD} = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
53 288 local ($!, $?);
54 288 $singleton->emit('SIG_CHLD');
55 288 ▶ return unless $singleton->collect_status;
Branch: 1 branch
BranchTrueFalseTotal
unless $singleton->collect_status 2 286 288
56 286 ▶ while ((my $pid = waitpid(-1, WNOHANG)) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $pid = waitpid(-1, 1)) > 0) 273 286 559
57 273 $singleton->add_collected_info($pid, $?, $!);
58 }
59 $singleton->consume_collected_info()
60 286 ▶ if ($singleton->emit_from_sigchld());
Branch: 1 branch
BranchTrueFalseTotal
if $singleton->emit_from_sigchld 277 9 286
61 }
62 85 });
63 }
64  
65 224 ▶sub _collect {
Subroutine _collect: called CC=1 SCAR=0.0
66 224 my ($self, $pid, $status, $errno) = @_;
67 224 my $p = $singleton->resolve($pid);
68 224 $p->emit('SIG_CHLD')
69 ->emit(collect_status => $pid => $status => $errno)
70 ->emit('collected')
71 ->emit('stop');
72 }
73  
74 273 ▶sub collect {
Subroutine collect: called CC=2 SCAR=6.9
Pod documented
75 273 my ($self, $pid, $status, $errno) = @_;
76 273 ▶ if ($singleton->resolve($pid)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($singleton->resolve($pid)) { } 224 49 273
77 224 $singleton->_collect($pid => $status => $errno);
78 224 $singleton->emit(collected => $singleton->resolve($pid));
79 }
80 else {
81 49 $singleton->orphans->{$pid}
82 = Mojo::IOLoop::ReadWriteProcess->new(process_id => $pid)
83 ->_fork_collect_status($pid => $status => $errno);
84 49 $singleton->emit(collected_orphan => $singleton->orphan($pid));
85 }
86 273 return $singleton;
87 }
88  
89 2905 ▶sub consume_collected_info {
Subroutine consume_collected_info: called CC=2 SCAR=6.9
Pod undocumented
90 2905 ▶ while (my $i = shift @{$singleton->collected_info}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $i = shift @{$singleton->collected_info;}) 273 2905 3178
91 273 $singleton->collect(@$i);
92 }
93 }
94  
95 273 ▶sub add_collected_info {
Subroutine add_collected_info: called CC=1 SCAR=0.0
Pod undocumented
96 273 shift;
97 273 push @{$singleton->collected_info}, [@_];
98 }
99  
100 # Use as $pid => Mojo::IOLoop::ReadWriteProcess
101 311 ▶sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod documented
102 311 my ($process, $pid) = (pop, pop);
103 311 $singleton->process_table()->{$pid} = \$process;
104 311 $singleton->emit(register => $process);
105 }
106  
107 1 ▶sub unregister { delete($singleton->process_table()->{+pop()}) }
Subroutine unregister: called CC=1 SCAR=0.0
Pod documented
108  
109 776 ▶sub _resolve {
Subroutine _resolve: called CC=3 SCAR=11.0
110 776 my ($el, $w) = (pop, pop);
111 return
112 exists $singleton->{$w}->{$el}
113 ? $w eq 'orphans'
114 ? $singleton->{$w}->{$el}
115 776 ▶ : ${$singleton->{$w}->{$el}}
Branch: 2 branches
BranchTrueFalseTotal
exists $singleton->{$w}{$el} ? : 726 50 776
$w eq 'orphans' ? : 49 677 726
116 : undef;
117 }
118 49 ▶sub orphan { _resolve(orphans => pop()) }
Subroutine orphan: called CC=1 SCAR=0.0
Pod documented
119 727 ▶sub resolve { _resolve(process_table => pop()) }
Subroutine resolve: called CC=1 SCAR=0.0
Pod documented
120  
121 2 ▶sub clean {
Subroutine clean: called CC=5 SCAR=17.8
Pod documented
122 $_[0]->resolve($_)->stop() and $_[0]->resolve($_)->DESTROY()
123 2 ▶ for keys %{$_[0]->process_table()};
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->resolve($_)->stop and $_[0]->resolve($_)->DESTROY 2 0 2
124 $_[0]->orphan($_)->stop() and $_[0]->orphan($_)->DESTROY()
125 2 ▶ for keys %{$_[0]->orphans()};
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->orphan($_)->stop and $_[0]->orphan($_)->DESTROY 0 0 0
126 2 shift->reset();
127 }
128  
129 43 ▶sub all { c($singleton->all_processes, $singleton->all_orphans)->flatten }
Subroutine all: called CC=1 SCAR=0.0
Pod documented
130 55 ▶sub all_orphans { c(values %{$singleton->orphans}) }
Subroutine all_orphans: called CC=1 SCAR=0.0
Pod documented
131  
132 53 ▶sub all_processes {
Subroutine all_processes: called CC=1 SCAR=0.0
Pod documented
133 53 ▶ c(values %{$singleton->process_table})->map(sub { ${$_} });
Subroutine __ANON__: called CC=1 SCAR=0.0
134 }
135  
136 30 ▶sub contains {
Subroutine contains: called CC=1 SCAR=0.0
Pod documented
137 30 my $pid = pop;
138 30 ▶ $singleton->all->grep(sub { $_->pid eq $pid })->size == 1;
Subroutine __ANON__: called CC=1 SCAR=0.0
139 }
140  
141 56 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
142 56 @{+shift}
143 56 {qw(events orphans process_table collected_info handler emit_from_sigchld)}
144 = ({}, {}, {}, [], undef, 1);
145 }
146  
147 # XXX: This should be replaced by PR_GET_CHILD_SUBREAPER
148 7 ▶sub disable_subreaper {
Subroutine disable_subreaper: called CC=2 SCAR=7.6
Pod documented
149 7 ▶ $singleton->subreaper(
Branch: 1 branch
BranchTrueFalseTotal
$singleton->_prctl(36, 0) == 0 ? : 7 0 7
150 $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 0) == 0 ? 0 : 1);
151 }
152  
153 47 ▶sub enable_subreaper {
Subroutine enable_subreaper: called CC=2 SCAR=7.6
Pod documented
154 47 ▶ $singleton->subreaper(
Branch: 1 branch
BranchTrueFalseTotal
$singleton->_prctl(36, 1) == 0 ? : 47 0 47
155 $singleton->_prctl(PR_SET_CHILD_SUBREAPER, 1) == 0 ? 1 : 0);
156 }
157  
158 122 ▶sub _get_prctl_syscall {
Subroutine _get_prctl_syscall: called CC=19 SCAR=50.9
159  
160 # Courtesy of Sys::Prctl
161 122 ▶ confess "Only Linux is supported" unless $^O eq 'linux';
Branch: 1 branch
BranchTrueFalseTotal
unless $^O eq "linux" 0 122 122
162  
163 122 my $machine = (POSIX::uname())[4];
164 122 ▶ die "Could not get machine type" unless $machine;
Branch: 1 branch
BranchTrueFalseTotal
unless $machine 0 122 122
165  
166 # if we're running on an x86_64 kernel, but a 32-bit process,
167 # we need to use the i386 syscall numbers.
168 122 ▶ $machine = "i386" if ($machine eq "x86_64" && $Config{ptrsize} == 4);
Branch: 1 branch
BranchTrueFalseTotal
if $machine eq "x86_64" and $Mojo::IOLoop::ReadWriteProcess::Session::Config{"ptrsize"} == 4 0 122 122
Condition33%1/3
$machine eq "x86_64" and $Mojo::IOLoop::ReadWriteProcess::Session::Config{"ptrsize"} == 4
!ll&&!rl&&r
01220
MC/DC0%0/2
$machine eq "x86_64" and $Mojo::IOLoop::ReadWriteProcess::Session::Config{"ptrsize"} == 4
$machine eq "x86_64" $Mojo::IOLoop::ReadWriteProcess::Session::Config{"ptrsize"} == 4
Truth table33%1/3
A and B
A= $machine eq "x86_64"B= $Mojo::IOLoop::ReadWriteProcess::Session::Config{"ptrsize"} == 4
ABresult
0X0
100
111
169  
170 122 ▶ my $prctl_call
Branch: 11 branches
BranchTrueFalseTotal
$machine =~ /^i[3456]86|^blackfin|cris|frv|h8300|m32r|m68k|microblaze|mn10300|sh|s390|parisc$/u ? : 0 122 122
$machine eq 'x86_64' ? : 122 0 122
$machine eq 'sparc64' ? : 0 0 0
$machine eq 'aarch64' ? : 0 0 0
$machine eq 'ppc' || $machine eq 'ppc64le' ? : 0 0 0
$machine eq 'ia64' ? : 0 0 0
$machine eq 'alpha' ? : 0 0 0
$machine eq 'avr32' ? : 0 0 0
$machine eq 'mips' ? : 0 0 0
$machine eq 'mips64' ? : 0 0 0
$machine eq 'xtensa' ? : 0 0 0
Condition0%0/3
$machine eq "ppc" or $machine eq "ppc64le"
l!l&&r!l&&!r
000
MC/DC0%0/2
$machine eq "ppc" or $machine eq "ppc64le"
$machine eq "ppc" $machine eq "ppc64le"
Truth table0%0/3
A or B
A= $machine eq "ppc"B= $machine eq "ppc64le"
ABresult
1X1
011
000
171 = $machine
172 =~ /^i[3456]86|^blackfin|cris|frv|h8300|m32r|m68k|microblaze|mn10300|sh|s390|parisc$/
173 ? 172
174 : $machine eq "x86_64" ? 157
175 : $machine eq "sparc64" ? 147
176 : $machine eq "aarch64" ? 167
177 : ($machine eq "ppc" || $machine eq "ppc64le") ? 171
178 : $machine eq "ia64" ? 1170
179 : $machine eq "alpha" ? 348
180 : $machine eq "avr32" ? 148
181 : $machine eq "mips" ? 4000 + 192
182 : $machine eq "mips64" ? 5000 + 153
183 : $machine eq "xtensa" ? 130
184 : undef;
185  
186 122 ▶ unless (defined $prctl_call) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prctl_call) 0 122 122
187 delete @INC{
188 0 qw<syscall.ph asm/unistd.ph bits/syscall.ph _h2ph_pre.ph
189 sys/syscall.ph>
190 };
191 0 my $rv = eval { require 'syscall.ph'; 1 } ## no critic
192 0 ▶ or eval { require 'sys/syscall.ph'; 1 }; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
my $rv = eval { do { require "syscall.ph"; 1 } } or eval { do { require "sys/syscall.ph"; '???' } } 0 0 0
193  
194 0 $prctl_call = eval { &SYS_prctl; };
195 }
196 122 return $prctl_call;
197 }
198  
199 61 ▶sub _prctl {
Subroutine _prctl: called CC=8 SCAR=22.5
200 61 my ($self, $option, $arg2, $arg3, $arg4, $arg5) = @_;
201 61 ▶ confess 'prctl not supported in this platform!'
Branch: 1 branch
BranchTrueFalseTotal
unless defined _get_prctl_syscall() 0 61 61
202 unless defined _get_prctl_syscall;
203 61 local $!;
204 61 ▶ my $ret = syscall(
Condition62%5/8
$arg2 || 0
l!l
547
$arg3 || 0
l!l
061
$arg4 || 0
l!l
061
$arg5 || 0
l!l
061
MC/DC100%1/1
$arg2 || 0
$arg2
MC/DC0%0/1
$arg3 || 0
$arg3
MC/DC0%0/1
$arg4 || 0
$arg4
MC/DC0%0/1
$arg5 || 0
$arg5
Truth table100%2/2
A
A= $arg2
Aresult
11
00
Truth table50%1/2
A
A= $arg3
Aresult
11
00
Truth table50%1/2
A
A= $arg4
Aresult
11
00
Truth table50%1/2
A
A= $arg5
Aresult
11
00
205 _get_prctl_syscall(), $option,
206 ($arg2 or 0),
207 ($arg3 or 0),
208 ($arg4 or 0),
209 ($arg5 or 0));
210  
211 61 ▶ warn "prctl($option) is unavailable on this platform." if $!{EINVAL};
Branch: 1 branch
BranchTrueFalseTotal
if $!{"EINVAL"} 0 61 61
212 61 ▶ warn "Error! $!" if $!;
Branch: 1 branch
BranchTrueFalseTotal
if $! 0 61 61
213 61 return $ret;
214 }
215  
216 39 *singleton = \&new;
217 39 *session = \&new;
218 39 *protect = \&_protect;
219  
220 39 1;
221  
222 =encoding utf-8
223  
224 =head1 NAME
225  
226 Mojo::IOLoop::ReadWriteProcess::Session - Session manager for handling child processes.
227  
228 =head1 SYNOPSIS
229  
230 use Mojo::IOLoop::ReadWriteProcess::Session;
231 use Mojo::IOLoop::ReadWriteProcess qw(process);
232  
233 my $session = process()->session; # or Mojo::IOLoop::ReadWriteProcess::Session->singleton
234  
235 $session->enable; # Modifies your SIG_CHLD
236  
237 $session->on(collected => sub { warn "Process ".(shift->pid)." collected! "});
238 $session->on(collected_orphan => sub { warn "Orphan process collected! "});
239  
240 $session->enable_subreaper(); # Mark the current process as subreaper
241 $session->disable_subreaper(); # Disable subreaper
242  
243 $session->reset(); # Resets events and clear the process tables
244 $session->clean(); # Stop all processes that result as running and reset
245  
246  
247 =head1 DESCRIPTION
248  
249 Mojo::IOLoop::ReadWriteProcess::Session is a session manager for the collected processes
250  
251 =head1 EVENTS
252  
253 L<Mojo::IOLoop::ReadWriteProcess::Session> inherits all events from L<Mojo::EventEmitter> and can emit
254 the following new ones.
255  
256 =head2 SIG_CHLD
257  
258 $session->on(SIG_CHLD => sub {
259 my ($self) = @_;
260 ...
261 });
262  
263 Emitted when we receive SIG_CHLD.
264  
265 =head2 collected
266  
267 $session->on(collected => sub {
268 my ($self, $process) = @_;
269 ...
270 });
271  
272 Emitted when child process is collected and it's return status is available.
273  
274 =head2 protect
275  
276 $session->on(protect => sub {
277 my ($self, $detail) = @_;
278 my ($cb, $signal) = @$detail;
279 ...
280 });
281  
282 Emitted when protected callbacks are fired.
283  
284 =head2 collected_orphan
285  
286 $session->on(collected_orphan => sub {
287 my ($self, $process) = @_;
288 $process->pid;
289 $process->exit_status;
290 ...
291 });
292  
293 Emitted when child process is collected and it's exit status is available.
294 Note: here are collected processes that weren't created with L<Mojo::IOLoop::ReadWriteProcess>.
295  
296 =head2 register
297  
298 $session->on(register => sub {
299 my ($self, $process) = @_;
300 $process->pid;
301 $process->exit_status;
302 ...
303 });
304  
305 Emitted when a process is registering to a session.
306  
307 =head1 ATTRIBUTES
308  
309 L<Mojo::IOLoop::ReadWriteProcess::Session> inherits all attributes from L<Mojo::EventEmitter> and implements
310 the following new ones.
311  
312  
313 =head2 subreaper
314  
315 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
316 session->enable_subreaper;
317 my $process = Mojo::IOLoop::ReadWriteProcess->new(code => sub { print "Hello ".$_[1] }, args => "User" );
318 $process->start();
319 $process->on( stop => sub { shift()->disable_subreaper } );
320 $process->stop();
321  
322 # The process will print "Hello User"
323  
324 Mark the current process (not the child) as subreaper on start.
325 It's on invoker behalf to disable subreaper when process stops, as it marks the current process and not the
326 child.
327  
328 =head2 collect_status
329  
330 Defaults to C<1>, If enabled it will automatically collect the status of the children process.
331 Disable it in case you want to manage your process child directly, and do not want to rely on
332 automatic collect status. If you won't overwrite your C<SIGCHLD> handler,
333 the C<SIG_CHLD> event will be still emitted.
334  
335 =head2 handler()
336  
337 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
338 session->handler(sub {});
339  
340 Default handler for SIG_CHLD processing, used when C<disable()> is invoked.
341  
342 =head1 METHODS
343  
344 L<Mojo::IOLoop::ReadWriteProcess::Session> inherits all methods from L<Mojo::EventEmitter> and implements
345 the following new ones.
346  
347 =head2 enable()
348  
349 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
350 session->enable();
351  
352 Sets the SIG_CHLD handler.
353  
354 =head2 disable()
355  
356 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
357 session->disable();
358  
359 Disables the SIG_CHLD handler and reset with the previous one.
360  
361 =head2 enable_subreaper()
362  
363 use Mojo::IOLoop::ReadWriteProcess qw(process);
364 my $p = process()->enable_subreaper;
365 # or
366 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
367 session->enable_subreaper;
368  
369 Mark the current process (not the child) as subreaper.
370 This is used typically if you want to mark further children as subreapers inside other forks.
371  
372 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
373  
374 my $master_p = process(
375 sub {
376 my $p = shift;
377 $p->enable_subreaper;
378  
379 process(sub { sleep 4; exit 1 })->start();
380 process(
381 sub {
382 sleep 4;
383 process(sub { sleep 1; })->start();
384 })->start();
385 process(sub { sleep 4; exit 0 })->start();
386 process(sub { sleep 4; die })->start();
387 my $manager
388 = process(sub { sleep 2 })->subreaper(1)->start();
389 sleep 1 for (0 .. 10);
390 $manager->stop;
391 return session->all->size;
392 });
393  
394 $master_p->subreaper(1);
395 $master_p->on(collect_status => sub { $status++ });
396  
397 $master_p->on(stop => sub { shift()->disable_subreaper });
398 $master_p->start();
399 session->all->size();
400 ....
401  
402 =head2 disable_subreaper()
403  
404 use Mojo::IOLoop::ReadWriteProcess qw(process);
405 my $p = process()->disable_subreaper;
406  
407 Unset the current process as subreaper.
408  
409 =head2 prctl()
410  
411 use Mojo::IOLoop::ReadWriteProcess qw(process);
412 my $p = process();
413 $p->prctl($option, $arg2, $arg3, $arg4, $arg5);
414  
415 Internal function to execute and wrap the prctl syscall, accepts the same arguments as prctl.
416  
417 =head2 reset()
418  
419 use Mojo::IOLoop::ReadWriteProcess qw(session);
420 session->reset;
421  
422 Wipe the process tables.
423  
424 =head2 clean()
425  
426 use Mojo::IOLoop::ReadWriteProcess qw(session);
427 session->clean;
428  
429 Wipe the process tables, but before attempt to stop running procesess.
430  
431 =head2 all()
432  
433 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
434 my $collection = session->all;
435 $collection->size;
436  
437 Returns a L<Mojo::Collection> of L<Mojo::IOLoop::ReadWriteProcess> that belongs to a session.
438  
439 =head2 all_orphans()
440  
441 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
442 my $collection = session->all_orphans;
443 $collection->size;
444  
445 Returns a L<Mojo::Collection> of L<Mojo::IOLoop::ReadWriteProcess> of orphaned processes that belongs to a session.
446 They are automatically turned into a L<Mojo::IOLoop::ReadWriteProcess>, also if processes were created by C<fork()>.
447  
448 =head2 all_processes()
449  
450 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
451 my $collection = session->all_processes;
452 $collection->size;
453  
454 Returns a L<Mojo::Collection> of all L<Mojo::IOLoop::ReadWriteProcess> known processes that belongs to a session.
455  
456 =head2 contains()
457  
458 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
459 my $collection = session->contains(13443);
460 $collection->size;
461  
462 Returns true if the pid is contained in any of the process tables.
463  
464 =head2 resolve()
465  
466 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
467 my $process = session->resolve(12233);
468  
469 Returns the L<Mojo::IOLoop::ReadWriteProcess> process identified by its pid if belongs to the process table.
470  
471 =head2 orphan()
472  
473 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
474 my $process = session->orphan(12233);
475  
476 Returns the L<Mojo::IOLoop::ReadWriteProcess> process identified by its pid if belongs to the process table of unknown processes.
477  
478 =head2 register()
479  
480 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
481 my $process = session->register('pid' => Mojo::IOLoop::ReadWriteProcess->new);
482  
483 Register the L<Mojo::IOLoop::ReadWriteProcess> process to the session.
484  
485 =head2 unregister()
486  
487 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
488 my $process = session->unregister(123342);
489  
490 Unregister the corresponding L<Mojo::IOLoop::ReadWriteProcess> with the given pid.
491  
492 =head2 collect()
493  
494 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
495 my $process = session->collect(123342 => 0 => undef);
496  
497 Collect the status for the given pid.
498  
499 =head2 protect()
500  
501 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
502 use POSIX;
503  
504 my $return = session->protect(sub { print "Hello World\n" });
505  
506 session->protect(sub { print "Hello World\n" } => SIGTERM);
507  
508 Try to protect the execution of the callback from signal interrupts.
509  
510 =head1 EXPORTS
511  
512 =head2 session()
513  
514 use Mojo::IOLoop::ReadWriteProcess::Session qw(session);
515 session->enable_subreaper;
516  
517 Returns the L<Mojo::IOLoop::ReadWriteProcess::Session> singleton.
518  
519 =head1 DEBUGGING
520  
521 You can set the MOJO_EVENTEMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
522  
523 MOJO_EVENTEMITTER_DEBUG=1
524  
525 Also, you can set MOJO_PROCESS_DEBUG environment variable to get diagnostics about the process execution.
526  
527 MOJO_PROCESS_DEBUG=1
528  
529 =head1 LICENSE
530  
531 Copyright (C) Ettore Di Giacinto.
532  
533 This library is free software; you can redistribute it and/or modify
534 it under the same terms as Perl itself.
535  
536 =head1 AUTHOR
537  
538 Ettore Di Giacinto E<lt>edigiacinto@suse.comE<gt>
539  
540 =cut
« lib/Mojo/IOLoop/ReadWriteProcess.pm ↑ Summary lib/Mojo/IOLoop/ReadWriteProcess/Namespace.pm »