What's the right way to kill child processes in perl before exiting?

Posted by rarbox on Stack Overflow See other posts from Stack Overflow or by rarbox
Published on 2010-03-21T16:43:23Z Indexed on 2010/03/21 16:51 UTC
Read the original article Hit count: 390

Filed under:
|
|
|

I'm running an IRC Bot (Bot::BasicBot) which has two child processes running File::Tail but when exiting, they don't terminate. So I'm killling them using Proc::ProcessTable like this before exiting:

my $parent=$$;
my $proc_table=Proc::ProcessTable->new();
for my $proc (@{$proc_table->table()}) {
  kill(15, $proc->pid) if ($proc->ppid == $parent);
}

It works but I get this warning:

14045: !!! Child process PID:14047 reaped:
14045: !!! Child process PID:14048 reaped:
14045: !!! Your program may not be using sig_child() to reap processes.
14045: !!! In extreme cases, your program can force a system reboot
14045: !!! if this resource leakage is not corrected.

What else can I do to kill child processes? The forked process is created using the forkit method in Bot::BasicBot.

© Stack Overflow or respective owner

Related posts about perl

Related posts about poe