in reply to RE (tilly) 4: For all your forking needs..
in thread For all your forking needs..

That's all fine and dandy, but if you have more than one child, you can lose it in between intermittent calls to wait. Plus, if you use wait, you'll never know WHICH child exited. It will only tell you A child exited. That's not very friendly. For one child, this may be OK, but in most cases, you are dealing with more than one. wait() is NOT OK in any case! waitpid is the ONLY correct way to clean up child processes that are not allowed to become zombies.

Since Perl (built upon C) is an interpreted language, it will never be good with signals, but the least we can do is to use the better function to clean up the zombies! Using wait instead of waitpid is like using kill instead of sigqueue. Sure, it may work in your certain cases, but in the end, it's simply more beneficial to use the function that

  1. returns more information about the condition of the program
  2. allows more programmer extensibly- queued signals vs. unreliable signals/ blocking perhaps forever on wait at the same time creating a zombie vs. the solution to this exact problem
In short, i fail to grasp your argument on why anyone should use wait vs. waitpid. if you think it is bad advice to recommend a better function to get more info on the same problem, then that's something I've never heard before. It is my opinion (and that of Stevens) that wait should be replaced in EVERY case with waitpid simply because it will promote better programming practice. The WNOHANG flag bonus is reason enough to replace wait that might block forever if you've lost a zombie! Thanks for the interesting battle of books, but I'll stick with my waitpid.
AgentM Systems or Nasca Enterprises is not responsible for the comments made by AgentM- anywhere.
  • Comment on RE: RE (tilly) 4: For all your forking needs..

Replies are listed 'Best First'.
RE (tilly) 6: For all your forking needs..
by tilly (Archbishop) on Oct 13, 2000 at 09:08 UTC
    Did you even look at the example I gave?

    I used wait. I knew which child exited. All that the WNOHANG flag could have added is cause to tie up the CPU in a tight loop. And getting the right value would give you reason to load POSIX, which both slows down the code and makes it less portable!

    And for the record I was not telling people to use wait instead of waitpid. I was telling you that you are wrong when you say that wait is deprecated and particularly dangerous.

    Ironically not only is wait not dangerous when used correctly, but your advice all presumes that the programmer will use signals. In fact cautious programmers have read the documentation, see the warnings, and avoid signals in Perl. Your giving any advice based on your theories of how to write good signals is encouraging a practice that is dangerous in Perl.

    Not only that, but the fact that you get a more complex signal handler can cause its own problems. perlipc offers two signal handlers. You and Stevens blast the one that uses wait based on how a safe handler in C should be written. But it is unclear that the waitpid handler is any better. It is more complex, you spend more time in the handler (when any signal will crash you), and the fact that you are assigning to a hash means that eventually you may wind up having a malloc() happen behind your back which would probably cause you to dump core!

    Personally I just skip down to the big WARNING section, take that to heart and avoid both of them!

    A reply falls below the community's threshold of quality. You may see it by logging in.