gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 11:46:42 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com