H
Hal Vaughan
I have a Perl program that runs as a daemon, with a specified loop, doing
certain things at certain seconds of the minute (like at 5 seconds after
the start of the minute it runs one set of routines, 20 seconds later
another set, and 30 seconds after that, another set, sleeping between each
set of routines). At the end of the minute, I have it reaping any zombies
that have been created. One thing it does is launch programs. To do this,
I fork() and run the program with backticks around the program name. For
some reason, after I've launched a program, if I call the reaper() routine
(below) before the launched program is done, the daemon will freeze in
reaper() until the launched program finishes.
So here's a few questions:
1) Do the unreaped zombies actually take up memory space, or just a number
in the list of PIDs?
2) I understand I can reap by setting $SIG{CHLD} to IGNORE, is that by just
using an assignment ($SIG{CHLD} = IGNORE), and how well does it work? The
name makes me think it just ignores zombies without doing anything.
3) Am I doing something wrong in the routines below, or is there a better
way to do this?
4) Why is the program hanging and waiting for the program that is still
running?
Thanks!
Hal
Subroutines:
#In the start, I have:
use POSIX ":sys_wait_h";
our $zombies = 0;
$SIG{CHLD} = sub{ $zombies++ };
Then I have a routine I call at the end of each loop the daemon makes:
sub reaper {
my (%Kid_Status)
if ($zombies) {
print "Zombie count: $zombie\n";
while (($zombie = waitpid(-1, WNOHANG)) != -1) {
$Kid_Status{$zombie} = $?;
}
}
return;
}
certain things at certain seconds of the minute (like at 5 seconds after
the start of the minute it runs one set of routines, 20 seconds later
another set, and 30 seconds after that, another set, sleeping between each
set of routines). At the end of the minute, I have it reaping any zombies
that have been created. One thing it does is launch programs. To do this,
I fork() and run the program with backticks around the program name. For
some reason, after I've launched a program, if I call the reaper() routine
(below) before the launched program is done, the daemon will freeze in
reaper() until the launched program finishes.
So here's a few questions:
1) Do the unreaped zombies actually take up memory space, or just a number
in the list of PIDs?
2) I understand I can reap by setting $SIG{CHLD} to IGNORE, is that by just
using an assignment ($SIG{CHLD} = IGNORE), and how well does it work? The
name makes me think it just ignores zombies without doing anything.
3) Am I doing something wrong in the routines below, or is there a better
way to do this?
4) Why is the program hanging and waiting for the program that is still
running?
Thanks!
Hal
Subroutines:
#In the start, I have:
use POSIX ":sys_wait_h";
our $zombies = 0;
$SIG{CHLD} = sub{ $zombies++ };
Then I have a routine I call at the end of each loop the daemon makes:
sub reaper {
my (%Kid_Status)
if ($zombies) {
print "Zombie count: $zombie\n";
while (($zombie = waitpid(-1, WNOHANG)) != -1) {
$Kid_Status{$zombie} = $?;
}
}
return;
}