File: paddrspacesize

package info (click to toggle)
hxtools 20201116-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,696 kB
  • sloc: ansic: 5,074; perl: 3,589; cpp: 2,152; sh: 1,610; asm: 173; makefile: 153
file content (34 lines) | stat: -rwxr-xr-x 745 bytes parent folder | download | duplicates (2)
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
31
32
33
34
#!/usr/bin/perl
#
#	Print size of adress space
#	written by Jan Engelhardt, 2007
#
#	This program is free software; you can redistribute it and/or
#	modify it under the terms of the WTF Public License version 2 or
#	(at your option) any later version.
#

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;
}