Linux:如何检查进程可用的最大连续地址范围

标签 linux memory-management mmap memory-fragmentation

我想在命令行输入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/

相关文章:

c - mmap 和 struct(类型错误 struct 与 void * 不兼容)

ios - 是否有人能够在 iOS 上使用 Address-Sanitizer(称为 asan 或 -fsanitize=address)?

linux - 使用 Sudo 命令时,单行中的多个命令不起作用

linux - 在 Puppet 中为/etc/fstab 使用 augeas 时遇到问题

linux - CUPS绕过接口(interface)

c - 将用户生成的节点添加到 C 中链表的末尾

使用 100% CPU 的 C++ 编译代码

linux - 让 linux 将内存更改持久保存到磁盘

mysql - 如何加快存储过程中的迭代插入过程?

c++ - C/C++ 与 GCC : Statically add resource files to executable/library