Hi,
I have a script that forks itself into background and after some other work it checks system load with Linux::loadavg. At first I also tried Sys::Statistics::Linux::LoadAVG. Whatever I try when the system load is higher and loop which check it kicks in after 2-3 iterations the process just silently dies. At first I tried wrapping it in an eval block. Then I enabled core dumps on my machine and at least I tried to use Debug::FaultAutoBT to check why the process is just dying.
Here's the sub which checks for systemload which just dies after 2-3 iterations in the loop
# config
my $avg1_limit = '4.0';
my $avg5_limit = '2.0';
sub check_load {
DEBUG("Enabling Auto Backtrace with output directory: '" . $tmp_dir
+. "'");
Debug::FaultAutoBT->new(dir => "$tmp_dir")->ready;
my $current_dir = getcwd;
DEBUG("check load is running from directory: '" . $current_dir . "'"
+);
my @avgs = loadavg();
my $load = { avg_1 => $avgs[LOADAVG_1MIN], avg_5 => $avgs[LOADAVG_5M
+IN], avg_15 => $avgs[LOADAVG_15MIN] };
my $dumper = Data::Dumper->new([$load],[qw($load)]);
DEBUG("current system load is: " . $dumper->Dump());
INFO("waiting for loads to drop below '1 min=$avg1_limit, 5 min=$avg
+5_limit'");
eval {
while ($load->{'avg_1'} > $avg1_limit or $load->{'avg_5'} >
+$avg5_limit) {
sleep(5);
DEBUG('about to call "loadavg"');
@avgs = loadavg();
$load = { avg_1 => $avgs[LOADAVG_1MIN], avg_5 => $avgs[LOA
+DAVG_5MIN], avg_15 => $avgs[LOADAVG_15MIN] };
DEBUG("... re-ckeck system load: " . $dumper->Dump());
}
};
if ($@) {
ERROR "failed checking load, error: $@";
}
else {
DEBUG "while loop ended nicely";
}
INFO("finished waiting, system load is now: " . Data::Dumper->Dump([
+$load],[qw($load)]));
}
Maybe also interesting is that I use Log4Perl to print DEBUG messages to logfile. Here's what it looks like when it stops in the middle of nowhere.
2019/10/24 04:56:21 DEBUG [29280] Enabling Auto Backtrace with output
+directory: '/tmp/cores'
2019/10/24 04:56:21 DEBUG [29280] check load is running from directory
+: '/'
2019/10/24 04:56:21 DEBUG [29280] current system load is: $load = {
'avg_5' => '2.34',
'avg_1' => '2.31',
'avg_15' => '2.28'
};
2019/10/24 04:56:21 INFO [29280] waiting for loads to drop below '1 mi
+n=4.0, 5 min=2.0'
2019/10/24 04:56:26 DEBUG [29280] about to call "loadavg"
2019/10/24 04:56:26 DEBUG [29280] ... re-ckeck system load: $load = $l
+oad;
2019/10/24 04:56:31 DEBUG [29280] about to call "loadavg"
2019/10/24 04:56:31 DEBUG [29280] ... re-ckeck system load: $load = $l
+oad;
What's puzzling me here actuall is the 2nd and following print of the Dumper so the lines starting with "... re-check system load" which pints just $load = $load instead of $load = { .... } but even without this message the script just stops here dead in its tracks without triggerint Debug::FaultAutoBT or producing a coredump.
I'm trying to figure why this isn't working since weeks now and I'm really out of ideas. Maybe it has to do with the fact that it's forked background process or that it repeatedly calls loadavg but I think it must be something else.
Any help is greatly appreciated cause I'm really starting to question perl here greatly. I've actually 10+ year of pressional perl experience but I never encountered a think like this...