我想在命令行输入pid,取回未被保留的最大连续地址空间。有任何想法吗?
我们的 32 位应用程序在 64 位 RHEL 5.4 上运行,运行一段时间后(比如 24 小时)就会崩溃。当时仅使用了 2.5 GB 的内存,但我们遇到了内存不足的错误。我们认为它无法映射大文件,因为应用程序的内存空间是碎片化的。我想进入生产服务器并测试该理论。
最佳答案
我上述评论的稍微好一点的版本:
#!perl -T
use warnings;
use strict;
scalar(@ARGV) > 0 or die "Use: $0 <pid>";
my $pid = $ARGV[0];
$pid = oct($pid) if $pid=~/^0/; # support hex and octal PIDs
$pid += 0; $pid = abs(int($pid)); # make sure we have a number
open(my $maps, "<", "/proc/".$pid."/maps") or
die "can't open maps file for pid ".$pid;
my $max = 0;
my $end = 0;
while (<$maps>) {
/([0-9a-f]+)-([0-9a-f]+)/;
$max = hex ($1) - $end if $max < hex ($1) - $end;
$end = hex ($2);
}
close ($maps);
END {
print "$max\n";
}
关于Linux:如何检查进程可用的最大连续地址范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9403146/