开发者

Perl script is getting killed during sleep()

I have a quite simple perl script, that in one function does the following:

    if ( legato_is_up() ) {
        write_log("INFO:        Legato is up and running. Continue the installation.");
        $wait_minutes = $WAITPERIOD + 1;
        $legato_up = 1;
    }
    else {
        my $towait = $WAITPERIOD - $wait_minutes;
        write_log("INFO:        Legato is not up yet. Waiting for another $towait minutes...");
        sleep 30;开发者_运维知识库
        $wait_minutes = $wait_minutes + 0.5;
    }

For some reason, sometimes (like 1 in 3 runs) the script gets killed. I don't know who's responsible for the kill, I just know it happens during the "sleep" call.

Can anyone give me a hint here? After script is killed, it's job is not done, which is a big problem.


Without knowing what else is running on your system, it's anybody's guess. You could add a signal handler, but all that it would tell you is which signal it was (and when), but not who sent it:

foreach my $signal (qw(INT PIPE HUP))
{
    my $old_handler = $SIG{$signal};
    $SIG{$signal} = sub {
        print time, ": ", $signal, " received!\n";
        $old_handler->(@_) if $old_handler;
    };
}

You also may want to consider adding a WARN and DIE handler, if you are not logging output from stderr.


Under, at least Linux, you can see who sent a signal (if its an external process that used kill(2)) by looking at the siginfo struct (particularly si_pid) passed to a signal handler. I don't know how to see that from Perl however - but in your case you could strace (or similar on non-Linux platforms) your script and see it that way. e.g. strace -p <pid of your perl script>. You should see something like:

--- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=89165, si_uid=1000} ---

just before your untimely death.

(a few years late for the OP I know...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜