in reply to Re^2: Fork() Function
in thread Fork() Function
Keep in mind that perl fork does not return -1, it returns undef on failure. In your code, fork failure results in system() and exit() on the parent side. A useful idiom with fork is my $pid = fork() // die; you may want if (!defined $pid) {} else if ($pid) {} else {}.
Keep in mind that a call to system results in another fork and wait, hence your work runs in a child of a child. You may have intended a direct exec instead of system.
Your OP question is somewhat ambiguous. Just in case, I'll mention that there is no guarantee that a newly spawned child has a different pid from some earlier (already reaped) process. Pid numbers are recycled.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Fork() Function
by carlriz (Beadle) on May 14, 2014 at 15:03 UTC | |
by morgon (Priest) on May 14, 2014 at 15:27 UTC |