in reply to fork question

If you want to see whether you're in the parent or the child do something like this:
while ($pid = fork()) { if ($pid) { print "$pid\n"; #returns nonzero in the parent } else { print "$pid\n"; #returns zero in the child } }
-Adam Stanley
Nethosters, Inc.

Replies are listed 'Best First'.
Re: Re: fork question
by suaveant (Parson) on Apr 11, 2001 at 23:57 UTC
    Umm, I just though it should be pointed out that your code exits the while loop if it is the child, and loops forever spawning off children like bionic rabbits if it is the parent... at least, it looks it. Child returns 0, so while loop fails, parent gets pid, enters loop, prints pid, forks again, ad nauseum
                    - Ant