develooper Front page | perl.perl5.porters | Postings from April 2010

Re: [PATCH] Attempt at improving the perlipc docs

Thread Previous | Thread Next
Maik Hentsche
April 22, 2010 11:44
Re: [PATCH] Attempt at improving the perlipc docs
Message ID:
Leon Timmermans <> wrote:

> Mentioning a problem is a good start, but what I'm missing is how to
> deal with this. That is far more valuable (and probably more
> complicated to do in a portable manner).

I think a short piece of code using waitpid would be a good
explanation. From my experience forking is most often used in daemon
environments so the code below should be a good start for most people.
It prevents the race condition in Eric's code and I don't see any new
issues. I'd appreciate your comments on the example below. I'm going to
improve my documentation changes with this:


sub do_cleanup
        do {
                $kid = waitpid(-1, WNOHUP);
                cleanup_child($kid) if $kid > 0;
        } while $kid > 0;

        my $pid = fork();
        if ($pid == 0){ 
             exit 0;
        } else {
             do_cleanup if $child_is_gone;

> Also, adding it three times may be an overkill. Personally don't think
> adding it to the system() documentation too adds much. You shouldn't
> be thinking about this when using system(), you should when using
> wait() IMO.

I agree. In perlfunc a link from wait() to perlipc should suffice. 

so long

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About