in reply to Perl Forking : perform some action until child process dies
Do you know what that next; is doing? Nothing. It's exiting a block you'd be exiting anyway.
As for the loop waiting for waitpid to return something other than 0, my first guess is, since "doesn't work" is kind of vague, that it seems to you the loop never runs?
Update:Yeah, what kennethk said abut it being a blocking call. I didn't even think of that for some reason. I'm going to blame lack of sleep. That explains the same loop-never-seems-to-run behavior but for the correct reason. I'll put my bad guess in a readmore. That's easier to read than a strikethrough.
If the loop seems like it never runs, it's probably because your child finishes its work and exits rather more quickly than you expected. If the child exits before you ever wait for it, you'll immediately get a nonzero return from waitpid(). Try doing what you need to do in the parent once right after the fork before you perform the loop, and see if that helps.
If you're having some other version of "doesn't work", then more detail may be helpful.
|
|---|