in reply to Re^2: $? is -1???
in thread $? is -1???

With no arguments, the call to 'sleep' will sleep forever. Try something like 'sleep 1'.

Is there a reason you are using WNOHANG? It seems like you could just use the blocking form of waitpid (unless I'm missing something).

Other than that this looks ok. The main reason I mentioned waiting on each individual pid was that this comes in handy if your parent actually did use something like system().

Replies are listed 'Best First'.
Re^4: $? is -1???
by kscaldef (Pilgrim) on Jun 21, 2004 at 23:00 UTC

    Whoops! That was dumb.

    I put in the '1' and I also took out the WNOHANG since, as you point out, it isn't needed here. (I just copied from my signal handler, where it is desirable.)

    Now it seems to work completely as expected. I'm still curious as to why the signal handler has this wierd behavior, but I'm guessing the answer is that the docs that claim that post-5.7.3 has safely reentrant signal handling are not quite correct.

    Thanks!

      FWIW, if you took out WNOHANG, you shouldn't need to sleep at all (i.e. waitpid will do that for you at that point).