File::Tailを実行している 2 つの子プロセスを持つIRC ボット ( Bot::BasicBot ) を実行していますが、終了しても終了しません。したがって、終了する前に、次のようにProc::ProcessTableを使用してそれらを殺しています。
my $parent=$$;
my $proc_table=Proc::ProcessTable->new();
for my $proc (@{$proc_table->table()}) {
kill(15, $proc->pid) if ($proc->ppid == $parent);
}
動作しますが、次の警告が表示されます。
14045: !!! 子プロセス PID:14047 が取得されました: 14045: !!! 子プロセス PID:14048 リープ: 14045: !!! プログラムが sig_child() を使用してプロセスをリープしていない可能性があります。 14045: !!! 極端な場合、プログラムがシステムの再起動を強制する可能性があります 14045: !!! このリソースの漏れが修正されない場合。
子プロセスを強制終了するには、他に何ができますか? フォークされたプロセスは、 Bot::BasicBotのforkitメソッドを使用して作成されます。
サンプル スクリプト:
package main;
my $bot = SOMEBOT->new ( server => 'irc.dal.net', channels => ['#anemptychannel'] );
$SIG{'INT'} = 'Handler';
$SIG{'TERM'} = 'Handler';
sub Handler {
$bot->_stop('Leaving.');
}
$bot->run;
package SOMEBOT;
use base qw(Bot::BasicBot);
use File::Tail;
use Proc::ProcessTable;
sub irc_error_state { die if $_[10] =~ /Leaving\./; }
sub help { return; }
sub stop_state {
my $parent=$$;
my $proc_table=Proc::ProcessTable->new();
for my $proc (@{$proc_table->table()}) {
kill(15, $proc->pid) if ($proc->ppid == $parent);
}
die;
}
sub connected {
my $self = shift;
$self->forkit (
run => \&announcer,
body => '/home/somebody/somefile.txt',
channel => '#anemptychannel',
) unless $self->{log1};
$self->{log1} = 1;
$self->forkit (
run => \&announcer,
body => '/home/somebody/anotherfile.txt',
channel => '#anemptychannel',
) unless $self->{log2};
$self->{log2} = 1;
}
sub announcer {
my $announcefile = shift;
my $file=File::Tail->new(name => $announcefile, maxinterval=>5, adjustafter=>7);
while (defined(my $line=$file->read)) { chomp $line; print "$line\n"; }
}