Improve portability when fetching process memory - use ps rather than the proc filesystem

This commit is contained in:
Ian Gregory 2016-05-10 10:34:30 +01:00
parent a7cd64a4c7
commit 7c1d5521ed

View file

@ -1088,15 +1088,15 @@ sub is_open_port {
sub get_process_memory {
my $pid = shift;
return 0 unless -f "/proc/$pid/status";
my @pdata = grep { /RSS:/ } get_file_contents "/proc/$pid/status";
map { s/.*RSS:\s*(\d+)\s*kB\s*$/$1*1024/ge } @pdata;
return $pdata[0];
my @mem = `ps -p $pid -o rss`;
return 0 if scalar @mem != 2;
return $mem[1]*1024;
}
sub get_other_process_memory {
my @procs = `ps -eo pid,cmd`;
my @procs = `ps -eaxo pid,command`;
map {
s/.*PID.*//;
s/.*mysqld.*//;
s/.*\[.*\].*//;
s/^\s+$//g;