in reply to sigchild and $?

Is there a reason you don't use something like waitpid()?

FWIW, I've had -1 returned for $? in the past when I've set up SIGCHLD and then used perl's builtin fork/exec stuff (i.e. backticks, system(), qx()). I'm assuming perl (or the C library) sets up it's own waitpid() and/or sighandler for these expecting to reap the process and then I come along and screw things up with my SIGCHLD handler. Maybe someone with more wisdom can figure out how to do this right, but I tend to avoid setting up SIGCHLD and generally find that I don't need to.

bluto

Replies are listed 'Best First'.
Re: Re: sigchild and $?
by Chapter_01 (Initiate) on Oct 01, 2003 at 13:03 UTC
    I would love to say I had a reason for not using waitpid(), but that might be a stretch. I will play around with that a bit. I did find a work around - if interested:
    @ScriptMSG=`/run/some/script;/usr/echo "\$?"`; chomp(@ScriptMSG); $ExitCode=$ScriptMsg[$#ScriptMsg];
    -Bryan
      I wasn't thinking straight -- forget my comment about waitpid() which you would need if you did your own fork/exec. You don't need it with backticks. Basically backticks sets $? so you can check it directly (by using this code ripped from 'perldoc -f system'...
      $exit_value = $? >> 8; $signal_num = $? & 127; $dumped_core = $? & 128;
      bluto