Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: How to fork one and only one child process from a loop ?

by idsfa (Vicar)
on Mar 18, 2006 at 04:50 UTC ( #537641=note: print w/replies, xml ) Need Help??

in reply to How to fork one and only one child process from a loop ?

This skeleton has no error checking, but it does only spawn one child.

my $kidpid; while( ... loop condition ... ) { . . . if( ! $kidpid) { if(0 == ($kidpid=fork())) { # I'm the child exec { ... } die("How did I get here?"); } } # I'm the parent, keep doing stuff . . . # Before I loop, do a lame check to make sure kid # is still running. Ought to use a Proc:: Module $kidpid=0 if(! grep { m/^\s+$kidpid\s/ } `ps ax`); }

The intelligent reader will judge for himself. Without examining the facts fully and fairly, there is no way of knowing whether vox populi is really vox dei, or merely vox asinorum. — Cyrus H. Gordon

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://537641]
[Corion]: choroba: Ooof! I can imagine that ;)
[Corion]: I think at a Perl workshop some years ago I gave two talks on the same day and after that decided to only submit one talk per event ;)
[LanX]: you play the triangle, right?
[choroba]: just one of its angles, in fact
[LanX]: <|--
[choroba]: Reminds me of an old joke about an orchestra...
erix imagines that in a true Lancs accent
[choroba]: so a Czech orchestra rehearses a new piece by a German composer

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2017-03-27 11:44 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (319 votes). Check out past polls.