G
Guest
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);
if($PROCS{$chld}){
my($obj) = delete($PROCS{$chld});
$obj->completed($?);
}
} until($chld == -1);
$SIG{CHLD} = \&REAPER; # Re-install.
}
$SIG{CHLD} = \&REAPER;
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.
....
system("ls");
($? >> 8) # Returns 161214215
# I don't have the actual number handy, but it's a long one.
I've got $SIG{PIPE} and $SIG{INT} 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?
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);
if($PROCS{$chld}){
my($obj) = delete($PROCS{$chld});
$obj->completed($?);
}
} until($chld == -1);
$SIG{CHLD} = \&REAPER; # Re-install.
}
$SIG{CHLD} = \&REAPER;
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.
....
system("ls");
($? >> 8) # Returns 161214215
# I don't have the actual number handy, but it's a long one.
I've got $SIG{PIPE} and $SIG{INT} 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?