steve abrams wrote:
> * code 'paraphrased' for simplicity *
>
> Hi all,
>
> I have a script which goes to a subroutine. Within the
> subroutine, there exists:
>
> $pid = fork;
> push(@pids, $pid);
> unless ($pid)
> {
> my $var = new Object;
> if (not $var->method_that_evokes_a_child()) {Exit;}
> exit 2;
> }
>
> where the Exit subroutine exits with a number other than 2. The parent
> process (before this subroutine is called), does a
>
> $foo = waitpid $pids[$count], &WNOHANG;
>
> and handles each child's return value.
>
> The problem I am having:
>
> CHILD_ERROR (or $?) on the outside of the subroutine is using the
> value from the child-evoking-method, ignoring the exit code I am
> giving. For example, if method_that_evokes_a_child exits with '1',
> the main parent gets '1' from its child, rather than '2' (the
> argument passed to 'exit()') if method was successful.
>
> So, perhaps I'm confused with how the final "exit" of a child behaves
> with regard to $?. If I don't call the child-evoking method, the
> original parent gets the "exit" code of the child. I want this to be
> the case even when I call the child-evoking method. Why does it not
> do this, and how can I 'fix' it?
>
> If anyone understands what I'm trying to explain, any help would be
> appreciated. Thanks!
I for one can't understand what you're trying to explain. Can you code up a
simple self-contained example that illustrates the problem (i.e. something
we can run)? I'm not clear on what you mean by "main parent" and
"child-evoking method", etc.
I will say that wait(2) only applies to immediate descendants, not
"grandchildren", if that's what you're doing...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>