in reply to Re: Re: Processes clobbering each other
in thread Processes clobbering each other
You are using open and thus the child's output is not being thrown into STDOUT but to a pipe. Closing all pipes without reading the output will not pipe the sub-process output to the parent's parent since they are on different pipes. You should probably use fork to fork(tm) without redirecting output to a different pipe. I managed to confuse myself with that last phrase so here's an idea:
$| = 1; $pid = open(first_child, "-|"); if ($pid) { while(<first_child>) { if ($_ =~ m/^Error/) { } #do nothin elsif ($_ =~ m/^Hits/) { push (@hits, $_) ; } else { push (@line, $_); } } } else { my @cpic; foreach $i(0..@gets) { $e = $gets[$i]; $c = $searches{$e}{handler}; $p = $FORM_DATA{p}; $q = $FORM_DATA{q}; $u = $searches{$e}{url}; $caller = "perl $c $p $q $u"; $cpid[$i] = fork; unless ($cpid[$i]) { system ($caller); exit; } } exit; }
Big warning! Untested code. I don't understand the task that you are trying to accomplish but I (hope) can now see what's wrong. This might not run but should give you an idea.
BTW: Why don't you use ForkManager to accomplish this task ? It simplifies debugging as it makes your code clearer and gives you more control on your child processes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Processes clobbering each other
by mcogan1966 (Monk) on Nov 25, 2003 at 13:50 UTC |