File: paddrspacesize

package info (click to toggle)
hxtools 20221119-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,760 kB
  • sloc: ansic: 5,114; perl: 3,612; cpp: 2,727; sh: 1,622; makefile: 156
file content (30 lines) | stat: -rwxr-xr-x 603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl
# SPDX-License-Identifier: MIT
#
#	Print size of adress space
#	written by Jan Engelhardt, 2007

use strict;
local *FH;

print "#### This script uses a heuristic, so may not be accurate\n";

my @list = `ps afhx -o pid,command`;
foreach my $line (@list) {
	my($pid, $reset) = ($line =~ /^\s*(\d+)\s+(.*)/);
	my $bitness = 0;

	if (!open(FH, "</proc/$pid/maps")) {
		next;
	}

	while (defined(my $subline = <FH>)) {
		$subline =~ /^([0-9a-f]+)/i;
		if ($bitness < length($1)) {
			$bitness = length($1);
		}
	}

	printf "[%2s] %s", $bitness == 0 ? "--" : 4 * $bitness, $line;
	close FH;
}