in reply to Waitpid Woes

On the one-liner, you are kicking out two child processes from the parent. Here's the code with indentation and decorations,

if (fork) { #in parent if (fork) { #in parent still waitpid -1, undef; print "-- ", $?>>8, "\n"; } else { # in second child exit 4; } } # else ??? # parent and first child drop off the end
Unix does not guarantee the order of execution of parent and child. If the parent runs first, the second child may exit 4 before the first child does a normal exit by falling off the end of the program.

There is a good chance of your one-liner leaving zombie the child that waitpid didn't see. I/O generally takes more than one timeslice, so the remaining child is apt to end its brief life during print and shamble about waiting for somebody to read its exit status.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Waitpid Woes
by suaveant (Parson) on Dec 18, 2003 at 16:46 UTC
    Yeah... unfortunately, this solves the mystery of my test, but not the problem with the real code. That is happening in a child process.

                    - Ant
                    - Some of my best work - (1 2 3)