in reply to meddling with forces I can't understand

exec never returns on success, so for(my $ct = 0; $ct <= $#forkArray; $ct+=3) never gets to execute its body more than once.

You never check if fork or exec succeeds.

You never reap your children.

If I'm not mistaken, you run in the parent what you want to run in the child.

The way in which @forkArray is used is not optimally readable.

for (...) { ... push(@forkArray, $level); push(@forkArray, $writeCounter); push(@forkArray, $nextMerge); } for (my $ct = 0; $ct <= $#forkArray; $ct+=3) { my $level = $forkArray[$ct+0]; my $mergeLast = $forkArray[$ct+1]; my $mergeFirst = $forkArray[$ct+2]; ... }

reads better as

for (...) { ... push @forkArray, [ $level, $writeCounter, $nextMerge ]; } foreach (@forkArray) { my ($level, $mergeLast, $mergeFirst) = $@_; ... }

Replies are listed 'Best First'.
Re^2: meddling with forces I can't understand
by downer (Monk) on Oct 25, 2007 at 00:30 UTC
    forgive me, but this is the first time i've done any of this. how do i manage these things?

    You never check if fork or exec succeeds.

    You never reap your children.

    If I'm not mistaken, you run in the parent what you want to run in the child.

    i have a feeling i'm running in the parent when i should be running in child too, but like i said, i'm not too sure what fork and exec do.

      You never check if fork or exec succeeds

      The documentation for fork and exec covers this.

      You never reap your children.

      I meant to provide a link to waitpid, one method of doing this.

      i'm not too sure what fork and exec do.

      fork creates a clone of the current process.
      exec replaces the program being run in the current process with another program.
      Check the docs of these functions, and perlipc.

Re^2: meddling with forces I can't understand
by downer (Monk) on Oct 25, 2007 at 00:30 UTC
    forgive me, but this is the first time i've done any of this. how do i manage these things? You never check if fork or exec succeeds. You never reap your children. If I'm not mistaken, you run in the parent what you want to run in the child. i have a feeling i'm running in the parent when i should be running in child too, but like i said, i'm not too sure what fork and exec do.