Fork, processes and exit codes?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Hello newsgroup:

I'm wondering about background processes and OSX.

I'm using a variant of the fairly standard child reaper:

sub REAPER {
        my $chld;
        do {
                $chld = waitpid(-1,&WNOHANG);
                        my($obj) = delete($PROCS);
        } until($chld == -1);
        $SIG = \&REAPER;  # Re-install.

Where %PROCS contains a mapping of pid <=> object.

The $obj->completed($?) method runs a callback function, (typically a bit
of code to update a status bar that the program terminated with xyz, this
status message, the ability to track the PID for killing/stopping/etc,
and backgrounding perl subs, is the whole reason for doing it this way
instead of system("cmd &"))

All works so far, but.. if I run programs _after_ a process terminates, in the
parent process with system(), the error code returned from those programs is
really messed up:

$proc->run($alert_callback); # Does fork, sets $PROCS = $obj;
.... &$alert_callback is run, indicated process is complete.
.... Ok, so now there aren't any background processes running.
($? >> 8) # Returns 161214215
          # I don't have the actual number handy, but it's a long one.

I've got $SIG and $SIG handlers installed for other reasons..
could this be messsing things up?

Do I need to do something in &REAPER to call perl's built in CHLD handler,
if %PROCS doesn't contain my PID?

-- Custom web programming
guhzo_42@lnubb.pbz (rot13)                User Management Solutions

Site Timeline