determining size of physical memory

Larry Wall lwall at jpl-devvax.JPL.NASA.GOV
Thu Jan 3 11:23:43 AEST 1991


In article <1369 at prcrs.UUCP> wrwalke at prcrs.UUCP (William Walker) writes:
: In article <7325 at plains.NoDak.edu>, bakke at plains.NoDak.edu (Jeffrey P. Bakke) writes:
: > In article <1990Dec27.202715.27688 at Neon.Stanford.EDU>, hitt at Neon.Stanford.EDU (Daniel Hitt) writes:
: > > Is there a standard UNIX program or system call that determines
: > > the size of the physical memory of the machine on which it is
: > > running?
: > > I'd like to be able to do this on Ultrix, SunOS, and the NeXT OS,
: > > and possibly HP-UX.
: > 
: > 'wc -c < /dev/mem' using the word count program to count the number of
: > bytes.  I've found on most systems that it will return the correct physical
: > memory size (not swap space though).  
: 
: or how about ...
: 
: dd if=/dev/mem of=/dev/null bs=1024 
: 
: this one is a try-at-you-own-risc solution, but it
: works on vax ultrix 3.1 and s800 hp-ux 7.0.

On a Sun you can derive it from the stuff the adb -k command prints out.
The following Perl script does this:

#!/usr/bin/perl

$ENV{'PATH'} = '/bin:/usr/bin';
unless (open(ADB,"-|")) {
    open(STDIN,'/dev/null');
    exec 'adb', '-k', '/vmunix', '/dev/mem';
    exit 1;
}

$_ = <ADB>;
$_ = <ADB> unless /^phys/;
close ADB;
($foo,$size) = split;

$size = (int(hex($size) / 0x100) + 1) * 2;
print $size,"\n";

Larry Wall
lwall at jpl-devvax.jpl.nasa.gov



More information about the Comp.unix.questions mailing list