ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.31 by root, Fri Nov 2 19:20:36 2007 UTC vs.
Revision 1.32 by root, Sat Nov 3 09:29:51 2007 UTC

176=head2 CHILD PROCESS WATCHERS 176=head2 CHILD PROCESS WATCHERS
177 177
178You can also listen for the status of a child process specified by the 178You can also listen for the status of a child process specified by the
179C<pid> argument (or any child if the pid argument is 0). The watcher will 179C<pid> argument (or any child if the pid argument is 0). The watcher will
180trigger as often as status change for the child are received. This works 180trigger as often as status change for the child are received. This works
181by installing a signal handler for C<SIGCHLD>. 181by installing a signal handler for C<SIGCHLD>. The callback will be called with
182the pid and exit status (as returned by waitpid).
182 183
183Example: wait for pid 1333 184Example: wait for pid 1333
184 185
185 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); 186 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" });
186 187
374our $CHLD_W; 375our $CHLD_W;
375our $PID_IDLE; 376our $PID_IDLE;
376our $WNOHANG; 377our $WNOHANG;
377 378
378sub _child_wait { 379sub _child_wait {
379 while (0 < (my $pid = waitpid -1, $WNOHANG)) { 380 while (0 <= (my $pid = waitpid -1, $WNOHANG)) {
380 $_->() for (values %{ $PID_CB{$pid} || {} }), 381 $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }),
381 (values %{ $PID_CB{0} || {} }); 382 (values %{ $PID_CB{0} || {} });
382 } 383 }
383 384
384 undef $PID_IDLE; 385 undef $PID_IDLE;
385} 386}
386 387

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines