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

Comparing AnyEvent-Fork/Fork.pm (file contents):
Revision 1.57 by root, Sun Aug 25 17:38:43 2013 UTC vs.
Revision 1.59 by root, Fri Aug 30 12:06:48 2013 UTC

668} 668}
669 669
670=item $pid = $proc->pid 670=item $pid = $proc->pid
671 671
672Returns the process id of the process I<iff it is a direct child of the 672Returns the process id of the process I<iff it is a direct child of the
673process running AnyEvent::Fork>, and C<undef> otherwise. 673process running AnyEvent::Fork>, and C<undef> otherwise. As a general
674rule (that you cannot rely upon), processes created via C<new_exec>,
675L<AnyEvent::Fork::Early> or L<AnyEvent::Fork::Template> are direct
676children, while all other processes are not.
674 677
675Normally, only processes created via C<< AnyEvent::Fork->new_exec >> and 678Or in other words, you do not normally have to take care of zombies for
676L<AnyEvent::Fork::Template> are direct children, and you are responsible 679processes created via C<new>, but when in doubt, or zombies are a problem,
677to clean up their zombies when they die. 680you need to check whether a process is a diretc child by calling this
678 681method, and possibly creating a child watcher or reap it manually.
679All other processes are not direct children, and will be cleaned up by
680AnyEvent::Fork itself.
681 682
682=cut 683=cut
683 684
684sub pid { 685sub pid {
685 $_[0][PID] 686 $_[0][PID]
816 817
817Even if not used otherwise, the socket can be a good indicator for the 818Even if not used otherwise, the socket can be a good indicator for the
818existence of the process - if the other process exits, you get a readable 819existence of the process - if the other process exits, you get a readable
819event on it, because exiting the process closes the socket (if it didn't 820event on it, because exiting the process closes the socket (if it didn't
820create any children using fork). 821create any children using fork).
822
823=over 4
824
825=item Compatibility to L<AnyEvent::Fork::Remote>
826
827If you want to write code that works with both this module and
828L<AnyEvent::Fork::Remote>, you need to write your code so that it assumes
829there are two file handles for communications, which might not be unix
830domain sockets. The C<run> function should start like this:
831
832 sub run {
833 my ($rfh, @args) = @_; # @args is your normal arguments
834 my $wfh = fileno $rfh ? $rfh : *STDOUT;
835
836 # now use $rfh for reading and $wfh for writing
837 }
838
839This checks whether the passed file handle is, in fact, the process
840C<STDIN> handle. If it is, then the function was invoked visa
841L<AnyEvent::Fork::Remote>, so STDIN should be used for reading and
842C<STDOUT> should be used for writing.
843
844In all other cases, the function was called via this module, and there is
845only one file handle that should be sued for reading and writing.
846
847=back
821 848
822Example: create a template for a process pool, pass a few strings, some 849Example: create a template for a process pool, pass a few strings, some
823file handles, then fork, pass one more string, and run some code. 850file handles, then fork, pass one more string, and run some code.
824 851
825 my $pool = AnyEvent::Fork 852 my $pool = AnyEvent::Fork
873the communications socket. 900the communications socket.
874 901
875The process object becomes unusable on return from this function - any 902The process object becomes unusable on return from this function - any
876further method calls result in undefined behaviour. 903further method calls result in undefined behaviour.
877 904
878The point of this method is to give you a file handle thta you cna pass 905The point of this method is to give you a file handle that you can pass
879to another process. In that other process, you can call C<new_from_fh 906to another process. In that other process, you can call C<new_from_fh
880AnyEvent::Fork> to create a new C<AnyEvent::Fork> object from it, thereby 907AnyEvent::Fork $fh> to create a new C<AnyEvent::Fork> object from it,
881effectively passing a fork object to another process. 908thereby effectively passing a fork object to another process.
882 909
883=cut 910=cut
884 911
885sub to_fh { 912sub to_fh {
886 my ($self, $cb) = @_; 913 my ($self, $cb) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines