M
Mike Dowling
I'm having problems reaping my dead children.
I have written a perl script that starts a monster program that
determines optimal schedules for my companies power plants. It can
happen that the optimisation software takes hours, months, or years.
Obviously, we would like to interrupt the program when that happens, but
my perl script is blocked until the monster finishes, or until it's
interrupted. So I start a second process with "fork" that writes info
from the log file that the monster is continually writing. I don't want
that second process to become a zombie, so I reap dead children ising:
use POSIX ":sys_wait_h";
$SIG{CHLD} = \&REAPER;
sub REAPER { # reap my dead children to avoid zombies
my $stiff;
while (($stiff = waitpid(-1, WNOHANG)) > 0) { }
$SIG{CHLD} = \&REAPER;
}
Now my child can rest in peace.
But, and here's the problem, if monster terminates with an error
message, I want to cath that, and analyse why. With any kind of
reaping, including
$SIG{CHLD} = 'IGNORE'
(I am really not interested in why my child dies), the status code
returned by monster is changed. I don't care that happens to dead
children started by "fork", but it is vital to check why a child dies
that is started with "system". What can be done?
Cheers,
Mike Dowling
I have written a perl script that starts a monster program that
determines optimal schedules for my companies power plants. It can
happen that the optimisation software takes hours, months, or years.
Obviously, we would like to interrupt the program when that happens, but
my perl script is blocked until the monster finishes, or until it's
interrupted. So I start a second process with "fork" that writes info
from the log file that the monster is continually writing. I don't want
that second process to become a zombie, so I reap dead children ising:
use POSIX ":sys_wait_h";
$SIG{CHLD} = \&REAPER;
sub REAPER { # reap my dead children to avoid zombies
my $stiff;
while (($stiff = waitpid(-1, WNOHANG)) > 0) { }
$SIG{CHLD} = \&REAPER;
}
Now my child can rest in peace.
But, and here's the problem, if monster terminates with an error
message, I want to cath that, and analyse why. With any kind of
reaping, including
$SIG{CHLD} = 'IGNORE'
(I am really not interested in why my child dies), the status code
returned by monster is changed. I don't care that happens to dead
children started by "fork", but it is vital to check why a child dies
that is started with "system". What can be done?
Cheers,
Mike Dowling