The following suggestions were made for determining physical memory.
I have not tested them all. Sysinfo seems to be the most often suggested
program for this as well as reporting a lot of other system information.
Many Thanks to ALL who responded
Joe McPherson
This is a long summary but I wanted to err on the side of
completeness.
Many Suggestions for sysinfo.
Some people pointed out that this is part of the FAQ for Sun Managers (oops!)
SYSINFO, DEVINFO, SHOWREV should give you all the
detailed info you want regarding the system.
Some suggestions to use adb.
For Solaris 2.x, try prtconf. For 4.x try /usr/diag/pmem
There is a small program available on the net called 'physmem'.
For solaris 2.X, use prtconf to see the memory size.
The program "vmpage" looks interesting.
For solaris 2.3 systems use /usr/kvm/prtdiag.
Several scripts/programs are included below.
---------------------------------------------------------------------
---------------------------------------------------------------------
A script form Richard Mills
#!/bin/ksh
#
# NAME:
# SunInfo
#
# PURPOSE:
# This script will give you a run down of the system configuration on
# a Sparc station with Solaris installed.
#
# DESCRIPTION:
# This script identifies the following attributes:
# Machine Name
# I.P. Address
# Machine Type
# Memory
# Devices
# Network Configuration
# Remote & Local Mounts
# Exported File Systems
echo "Creating `uname -n`.sysinfo"
echo "Working\c"
PATH=/bin:/usr/bin:/usr/ucb:/usr/sbin:.
NAME=`uname -n` ## get the name of the system ##
MACHINE=`hostid | cut -c1-2` ## get the identifier from the hostid ##
MEMORY=`prtconf | grep Mem | awk '{print $3, $4}'` ## get the amount of ##
## memory on the machine ##
IPADDRESS=`grep $NAME /etc/hosts | awk '{print $1}'` ## get I.P. address of ##
## machine ##
IMNT=`mount | awk '{print $3}' | grep \:` ## check if there are any ##
## filesystems that are ##
## remotely mounted ##
FREQ=0 ## initialize frequency ##
echo ".\c"
output="`uname -n`.sysinfo"
#
# Match up $MACHINE with the correct machine type.
#
if [ $MACHINE = 72 ]; then
MACHINE="Sparc 10"
elif [ $MACHINE = 55 ]; then
MACHINE="Sparc 2"
elif [ $MACHINE = 51 ]; then
MACHINE="Sparc 1"
else
MACHINE="Unknown"
fi
echo ".\c"
#
# Determine speed of the cpu
#
export FREQ
prtconf -vp | grep 'clock-frequency:' | while read pr_line
do
case $pr_line in
clock-frequency:*)
if [ "$FREQ" = 0 ]
then
set $pr_line
hex_freq=`echo $2 | tr '[a-z]' '[A-Z]'`
FREQ=` ( echo "ibase=16" ; echo $hex_freq ) | bc`
FREQ=`expr $FREQ \/ 100000 | sed 's/\(.*\)\(.\)/\1.\2/'`
else
set $pr_line
name_hex_freq=`echo $2 | tr '[a-z]' '[A-Z]'`
name_freq=` ( echo "ibase=16" ; echo $name_hex_freq ) | bc`
name_freq=`expr $name_freq \/ 100000 | sed 's/\(.*\)\(.\)/\1.\2/'`
fi
;;
esac
echo ".\c"
done
#
# Send information to the outfile.
#
echo "Run Date : `date +%A\ %d\ %I:%M\ %p\ %B\ %Y`" > $output
echo " " >> $output
echo "Machine Name : " $NAME >> $output
echo "I.P. Address : " $IPADDRESS >> $output
echo "Machine Type : " $MACHINE >> $output
echo "MHz : " $FREQ >> $output
echo "Memory : " $MEMORY >> $output
echo "===================" >> $output
echo ".\c"
#
# Get list of devices on a system.
#
df -k | tail +2 | sed 's/(//' | sed 's/)//' | \
while read line
do
set - ${line}
echo "Filesystem : ${1}" >> $output
echo "Kbytes : ${2}" >> $output
echo "Used : ${3}" >> $output
echo "Available : ${4}" >> $output
echo "Capacity : ${5}" >> $output
echo "Mounted on : ${6}" >> $output
echo "----------------------------------------------" >> $output
echo ".\c"
done
#
# Print out the network configuration for all ethernet cards.
#
echo "" >> $output
echo "Network Configuration : " >> $output
echo "------------------------" >> $output
ifconfig -a >> $output
echo ".\c"
#
# Find what filesystems are being remotely mounted.
#
echo "" >> $output
echo "Remote Mount Information : " >> $output
echo "-----------------------------------------------" >> $output
## check if any filesystems are remotely mounted ##
if [ -n "${IMNT}" ] ; then
## read in mount information ##
mount | \
while read line
do
## get only those filesystems that are remotely mounted ##
set - ${line}
RMTCHK=`expr ${3} : '\(.*:.*\)'`
FS=${1}
DEV=${3}
## Echo out only those file systems that are remotely mounted
if [ -n "$RMTCHK" ]; then
echo "File System : " $FS >> $output
echo "Node : " `echo $DEV | sed 's/:/\ :\ /g' | awk '{print $1}'` >> $output
echo "-----------------------------------------------" >> $output
fi
echo ".\c"
done
else
echo "Nothing is remotely mounted" >> $output
fi
#
# Find what filesystems are locally mounted.
#
echo "" >> $output
echo "Local Mount Information : " >> $output
echo "-----------------------------------------------" >> $output
## read in mount information ##
mount | \
while read line
do
## get only those filesystems that locally mounted ##
set - ${line}
RMTCHK=`expr ${3} : '\([^:]*\)$'`
FS=${1}
DEV=${3}
## Echo out only those file systems that are locally mounted
if [ -n "$RMTCHK" ]; then
echo "File System : " $FS >> $output
echo "Disk : " $DEV >> $output
echo "-----------------------------------------------" >> $output
fi
echo ".\c"
done
#
# Check for exported filesystems.
#
if [ -f /etc/dfs/sharetab ]; then
echo "" >> $output
echo "Exported File Systems : " >> $output
echo "-------------------------" >> $output
## read in exported filesystems stats ##
share | \
while read line
do
set - ${line}
echo "Filesystem : ${2}" >> $output
echo "Permissions : ${3}" >> $output
echo "-------------------------" >> $output
echo ".\c"
done
fi
echo " "
-- __________________________________ ///////////////////////////////////| ===================================/| ||Richard Mills ||/| ||System Administration ||/| ||Harris Controls Division ||/| ||Melbourne Florida ||/| ||(407)242-5324__________________||/| ||rmills@ccd.harris.com//////////||/| ===================================/--------------------------------------------------------------------- ---------------------------------------------------------------------
A utility from Jay Lessert
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # 'mem.c' # 'mem.man' # This archive created: Tue Jun 14 15:56:24 PDT 1994 # By: jayl export PATH; PATH=/bin:$PATH echo shar: extracting "'mem.c'" "(2680 characters)" if test -f 'mem.c' then echo shar: will not over-write existing file "'mem.c'" else sed 's/^X//' << \SHAR_EOF > 'mem.c' X/* X * $Header: /galileo0/jayl/pdsrc/mem/RCS/mem.c,v 1.5 1993/04/09 17:24:06 jayl Exp $ X * Figure out how much memory there is on a machine. This works under X * Berkeley UNIX. It should work under System V if you change the X * UNIX define to "/unix" instead of "/vmunix". X * X * Of course, if you don't have read permission on the kernel and X * kernel memory, this won't work. X * X * Dave Curry X * Purdue University X * Engineering Computer Network X * X * Hacked by Larry Breniser 10/1/91 X * Pagesize is now determied dynamically, not at copile X * time, as it varies from host to host (server vs workstation) X * X * davy@intrepid.ecn.purdue.edu X * $Header: /galileo0/jayl/pdsrc/mem/RCS/mem.c,v 1.5 1993/04/09 17:24:06 jayl Exp $ X * $Log: mem.c,v $ X * Revision 1.5 1993/04/09 17:24:06 jayl X * add -v (verbose) flag, report single physmem in KB by default. JDL X * X * Revision 1.4 1991/12/20 00:22:53 jdd X * Initial revision X * X * Revision 1.3 91/10/02 17:51:10 larryb X * Added Version string to executable for ident. X * X * Revision 1.2 91/10/02 17:46:21 larryb X * Added RCS log comments. X * X */ X#include <sys/param.h> X#include <sys/types.h> X#include <nlist.h> X#include <stdio.h> X#include <string.h> X Xchar version[] = "$Header: /galileo0/jayl/pdsrc/mem/RCS/mem.c,v 1.5 1993/04/09 17:24:06 jayl Exp $"; X X#define UNIX "/vmunix" X#define KMEM "/dev/kmem" X Xstruct nlist nl[] = { X#define X_PHYSMEM 0 X { "_physmem" }, X#define X_MAXMEM 1 X { "_maxmem" }, X { NULL } X}; X Xmain(argc,argv) Xint argc; Xchar *argv[]; X{ X int kmem; X int maxmem, physmem; X int pagesize; X int verbose = 0; X /* X * check command line arguments X */ X if (argc > 1) { X if (strcmp(argv[1], "-v")==0) { X verbose++; X } X else { X printf("Usage: %s [-v]\n", argv[0]); X exit(1); X } X } X /* X * Look up addresses of variables. X */ X if ((nlist(UNIX, nl) < 0) || (nl[0].n_type == 0)) { X fprintf(stderr, "%s: no namelist.\n", UNIX); X exit(1); X } X /* X * Open kernel memory. X */ X if ((kmem = open(KMEM, 0)) < 0) { X perror(KMEM); X exit(1); X } X /* X * Read variables. X */ X lseek(kmem, (long) nl[X_PHYSMEM].n_value, 0); X read(kmem, (char *) &physmem, sizeof(int)); X lseek(kmem, (long) nl[X_MAXMEM].n_value, 0); X read(kmem, (char *) &maxmem, sizeof(int)); X close(kmem); X pagesize=getpagesize(); X /* X * Print the numbers. The internal representation is X * in units of core clicks; convert to Kbytes for default X # or bytes for verbose. X */ X if (verbose) { X printf("Pagesize: %d\n", pagesize); X printf("Physical machine memory: %d\n", pagesize * physmem); X printf("Max memory available to a process: %d\n", pagesize * maxmem); X } X else { X printf("%d\n", pagesize * physmem / 1024); X } X exit(0); X} SHAR_EOF if test 2680 -ne "`wc -c < 'mem.c'`" then echo shar: error transmitting "'mem.c'" '(should have been 2680 characters)' fi fi # end of overwriting check echo shar: extracting "'mem.man'" "(820 characters)" if test -f 'mem.man' then echo shar: will not over-write existing file "'mem.man'" else sed 's/^X//' << \SHAR_EOF > 'mem.man' X.\" $Header: /bear/p0/pdsrc/mem/RCS/mem.man,v 1.1 92/02/12 13:00:05 jayl Exp $ X.TH MEM LBIT "12 Feb 1992" X.SH NAME Xmem \- report amount of physical memory present X.SH SYNOPSIS X.B mem X[ X.I -v X] X.SH DESCRIPTION X.LP X.I Mem Xscans /vmunix and /dev/kmem to determine the amount of physical Xmemory present. Page size is determined at runtime, so machines Xwith varying pagesizes are handled properly. Memory size is Xreported in KB. X.SH OPTIONS X.PD 0 X.TP 10 X.I -v XA little more verbose, plus a report of user-available memory is Xincluded (i.e., kernel-locked memory pages are subtracted). X.SH FILES X.PD 0 X.TP 16 X/vmunix Xthe default system namelist X.TP X/dev/kmem Xthe default system memory image X.PD X.SH "SEE ALSO" Xpagesize(1) X.SH BUGS XShould have command line args for non-default (System V) locations Xof /vmunix and /dev/kmem. SHAR_EOF if test 820 -ne "`wc -c < 'mem.man'`" then echo shar: error transmitting "'mem.man'" '(should have been 820 characters)' fi fi # end of overwriting check # End of shell archive exit 0
--------------------------------------------------------------------- ---------------------------------------------------------------------
Perl script from Rodney Campbell
#!/usr/gnu/bin/perl # # I think for Sun-3's you divide by 128 # $_ = `adb -k /vmunix /dev/mem </dev/null 2>&1`; if (/physmem\s+(.*)/) { print "Physical Mem: ", int(hex($1) / 256 + 1), " MB\n"; } else { die $_; }
--------------------------------------------------------------------- ---------------------------------------------------------------------
Nate Itkin issues the following command
echo "_physmem/D" | adb -k /vmunix /dev/mem | tail -1 | awk '{printf("Physical Memory = %d KB\n",$2*4)}'
--------------------------------------------------------------------- ---------------------------------------------------------------------
David Mitchell uses the following
/usr/diag/sundiag/pmem v /usr/diag/sundiag/pmem: Started. Read 0x400000 bytes (1024 pages) starting at address 0x0. Read 0x1000000 bytes (4096 pages) starting at address 0x1000000. Read 0x400000 bytes (1024 pages) starting at address 0x2000000. Physical memory = 0x1800000 (24 Meg) bytes. /usr/diag/sundiag/pmem: Stopped successfully
--------------------------------------------------------------------- ---------------------------------------------------------------------
Small c program from Andrej.Misik@fmph.uniba.sk
/* print amount of total physical memory */ #include <stdio.h> #include <unistd.h>
main () { long memb;
memb=sysconf(_SC_PAGESIZE)*sysconf(_SC_PHYS_PAGES); printf ("Physical memory in bytes : %ld\n",memb); printf ("Physical memory in Kbytes: %ld\n",memb/1024); printf ("Physical memory in Mbytes: %ld\n",memb/(1024*1024)); return 0; }
--------------------------------------------------------------------- ---------------------------------------------------------------------
Bill Heiser uses the following: /* * Program to determine the size installed physical memory on Suns. * * Casper Dik. */
#define MEGABYTE 0x00100000 #define MAXMEM 0x7ff00000 #define THEMEM "/dev/mem"
#include <stdio.h> #include <fcntl.h>
main() { int fd = open(THEMEM,O_RDONLY); char c; unsigned long pos, mapstart = 0; int totmb = 0;
if (fd == -1) { perror(THEMEM); exit(1); } for (pos = 0; pos < MAXMEM; pos += MEGABYTE) { if (lseek(fd,pos,0) == -1) { perror("lseek"); exit(1); } if (read(fd,&c,1) == -1) { int size = (pos-mapstart)/MEGABYTE; if (size != 0) { printf("found %3d MB starting at 0x%08x\n", size,mapstart); totmb += size; } mapstart = pos + MEGABYTE; /* start of next possible mapping */ } } printf("Total memory size: %d MB\n",totmb); exit(0); }
--------------------------------------------------------------------- ---------------------------------------------------------------------
Patrick Nolan suggest the following code
/* * Figure out how much memory there is on a machine. This works under * Berkeley UNIX. It should work under System V if you change the * UNIX define to "/unix" instead of "/vmunix". * * Of course, if you don't have read permission on the kernel and * kernel memory, this won't work. * * Dave Curry * Purdue University * Engineering Computer Network * * Hacked by Larry Breniser 10/1/91 * Pagesize is now determied dynamically, not at compile * time, as it varies from host to host (server vs workstation) * * davy@intrepid.ecn.purdue.edu * $Header: /src/mem/RCS/mem.c,v 1.4 1991/12/20 00:22:53 jdd Exp $ * $Log: mem.c,v $ * Revision 1.4 1991/12/20 00:22:53 jdd * Added a verbose option which behaves like the previous revision. * Changed the physmem figure to report memory in KBs * Added a usage message * Made the non -verbose default behave like the revision before the last. * * Revision 1.3 1991/10/15 19:52:26 jdd * *** empty log message *** * * Revision 1.2 1991/10/15 19:51:11 jdd * New version which works on machines with different page sizes. * * Revision 1.3 91/10/02 17:51:10 larryb * Added Version string to executable for ident. * * Revision 1.2 91/10/02 17:46:21 larryb * Added RCS log comments. * */ #include <sys/param.h> #include <sys/types.h> #include <nlist.h> #include <stdio.h>
char version[] = "$Header: /src/mem/RCS/mem.c,v 1.4 1991/12/20 00:22:53 jdd Exp$";
#define UNIX "/vmunix" #define KMEM "/dev/kmem"
struct nlist nl[] = { #define X_PHYSMEM 0 { "_physmem" }, #define X_MAXMEM 1 { "_maxmem" }, { NULL } };
main(argc, argv) int argc; char **argv; { int kmem; int maxmem, physmem; int pagesize; int verbose = 0;
if(argc>1){ if(0==strcmp("-v", argv[1])) { verbose=1; } else { fprintf(stderr, "Usage: %s [-v]\n", argv[0]); exit(1); } }
/* * Look up addresses of variables. */ if ((nlist(UNIX, nl) < 0) || (nl[0].n_type == 0)) { fprintf(stderr, "%s: no namelist.\n", UNIX); exit(1); }
/* * Open kernel memory. */ if ((kmem = open(KMEM, 0)) < 0) { perror(KMEM); exit(1); }
/* * Read variables. */ lseek(kmem, (long) nl[X_PHYSMEM].n_value, 0); read(kmem, (char *) &physmem, sizeof(int));
lseek(kmem, (long) nl[X_MAXMEM].n_value, 0); read(kmem, (char *) &maxmem, sizeof(int));
close(kmem);
pagesize=getpagesize();
/* * Print the numbers. The internal representation is * in units of core clicks; convert to bytes. */
if(verbose) printf("Pagesize: %d\n", pagesize);
if(verbose) { printf("Physical machine memory (KB): %d\n", (pagesize*physmem)/ 1024); } else { printf("%d\n", (pagesize * physmem)/1024); } if(verbose) printf("Max memory available to a process: %d\n", pagesize * maxmem);
exit(0); }
--------------------------------------------------------------------- --------------------------------------------------------------------- Tim Diebert gave this short example of using adb:
adb -k /vmunix /dev/mem physmem 5eeb $q aria# dc 16i -- input in hex 5EEB p -- convert to decimal 24299 Ai -- input in decimal 24299 4096 * p -- available memory 99528704 96 1024 * 1024 * p -- closest megabyte. 100663296 q
--------------------------------------------------------------------- --------------------------------------------------------------------- Steve Harris provided the following:
#! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # Makefile # getmemvars.c # memsize.c # seekmemsize.c # This archive created: Thu Jul 7 13:39:16 1994 export PATH; PATH=/bin:/usr/bin:$PATH echo shar: "extracting 'Makefile'" '(275 characters)' if test -f 'Makefile' then echo shar: "will not over-write existing file 'Makefile'" else sed 's/^ X//' << \SHAR_EOF > 'Makefile' XSOURCES = getmemvars.c memsize.c seekmemsize.c XOBJECTS = $(SOURCES:.c=.o) XTAGS = tags X Xall: memsize X Xmemsize: $(OBJECTS) X $(LINK.c) -o memsize $(OBJECTS) X Xtags: FORCE X ctags $(SOURCES) X Xclean: FORCE X $(RM) $(OBJECTS) $(TAGS) X Xsclean: clean FORCE X sccs clean X XFORCE: SHAR_EOF if test 275 -ne "`wc -c < 'Makefile'`" then echo shar: "error transmitting 'Makefile'" '(should have been 275 characters)' fi fi echo shar: "extracting 'getmemvars.c'" '(2059 characters)' if test -f 'getmemvars.c' then echo shar: "will not over-write existing file 'getmemvars.c'" else sed 's/^ X//' << \SHAR_EOF > 'getmemvars.c' X/* X * Figure out how much memory there is on a machine. This works under X * Berkeley UNIX. It should work under System V if you change the X * UNIX define to "/unix" instead of "/vmunix". X * X * Of course, if you don't have read permission on the kernel and X * kernel memory, this won't work. X * X * Dave Curry X * Purdue University X * Engineering Computer Network X * X * Hacked by Larry Breniser 10/1/91 X * Pagesize is now determied dynamically, not at copile X * time, as it varies from host to host (server vs workstation) X * X * davy@intrepid.ecn.purdue.edu X * $Header: /usr2/larryb/c/RCS/physmem.c,v 1.3 91/10/02 17:51:10 larryb Exp $ X * $Log: physmem.c,v $ X * Revision 1.3 91/10/02 17:51:10 larryb X * Added Version string to executable for ident. X * X * Revision 1.2 91/10/02 17:46:21 larryb X * Added RCS log comments. X * X */ X X#include <sys/param.h> X#include <sys/types.h> X#include <nlist.h> X#include <stdio.h> X X#define UNIX "/vmunix" X#define KMEM "/dev/kmem" X#ifndef dgm X#define MEG (1024 * 1024) X#endif X Xstruct nlist nl[] = X{ X#define X_PHYSMEM 0 X { "_physmem" }, X#define X_MAXMEM 1 X { "_maxmem" }, X { NULL } X}; X Xgetmemvars() X{ X int kmem; X int maxmem, physmem; X int pagesize; X X/* Look up addresses of variables. */ X if ((nlist(UNIX, nl) < 0) || (nl[0].n_type == 0)) X { X fprintf(stderr, "%s: no namelist.\n", UNIX); X return(1); X } X X/* Open kernel memory. */ X if ((kmem = open(KMEM, 0)) < 0) X { X perror(KMEM); X return(1); X } X X/* Read variables. */ X lseek(kmem, (long) nl[X_PHYSMEM].n_value, 0); X read(kmem, (char *) &physmem, sizeof(int)); X X lseek(kmem, (long) nl[X_MAXMEM].n_value, 0); X read(kmem, (char *) &maxmem, sizeof(int)); X X close(kmem); X X X pagesize=getpagesize(); X X/* convert to bytes */ X physmem *= pagesize; X maxmem *= pagesize; X X/* print the numbers in Mbytes */ X printf("Getting kernel memory size variables:\n"); X printf(" pagesize = %d bytes\n", pagesize); X printf(" physmem = %d (%0.3f MB)\n", X physmem, (float)physmem / (float)MEG); X printf(" maxmem = %d (%0.3f MB)\n", X maxmem, (float)maxmem / (float)MEG); X X return(0); X} SHAR_EOF if test 2059 -ne "`wc -c < 'getmemvars.c'`" then echo shar: "error transmitting 'getmemvars.c'" '(should have been 2059 characters)' fi fi echo shar: "extracting 'memsize.c'" '(64 characters)' if test -f 'memsize.c' then echo shar: "will not over-write existing file 'memsize.c'" else sed 's/^ X//' << \SHAR_EOF > 'memsize.c' Xmain() X{ X (void)seekmemsize(); X (void)getmemvars(); X exit(0); X} SHAR_EOF if test 64 -ne "`wc -c < 'memsize.c'`" then echo shar: "error transmitting 'memsize.c'" '(should have been 64 characters)' fi fi echo shar: "extracting 'seekmemsize.c'" '(971 characters)' if test -f 'seekmemsize.c' then echo shar: "will not over-write existing file 'seekmemsize.c'" else sed 's/^ X//' << \SHAR_EOF > 'seekmemsize.c' X/* X * Program to determine the size installed physical memory on Suns. X * X * Casper Dik. X */ X X#define MEGABYTE 0x00100000 X#define MAXMEM 0x7ff00000 X#define THEMEM "/dev/mem" X X#include <stdio.h> X#include <fcntl.h> X X Xseekmemsize() { X int fd = open(THEMEM,O_RDONLY); X char c; X unsigned long pos, mapstart = 0; X int totmb = 0; X X if (fd == -1) { X perror(THEMEM); X return(1); X } X printf("Determining memory size by seek and read:\n"); X for (pos = 0; pos < MAXMEM; pos += MEGABYTE) { X if (lseek(fd,pos,0) == -1) { X perror("lseek"); X return(1); X } X if (read(fd,&c,1) == -1) { X int size = (pos-mapstart); X if (size != 0) { X printf(" found %3d (%0.3f MB) starting at 0x%08x\n", X size, (float)size/(float)MEGABYTE, mapstart); X totmb += size; X } X mapstart = pos + MEGABYTE; /* start of next possible mapping */ X } X } X printf(" Total memory size: %d (%0.3f MB)\n", X totmb, (float)totmb/(float)MEGABYTE); X return(0); X} SHAR_EOF if test 971 -ne "`wc -c < 'seekmemsize.c'`" then echo shar: "error transmitting 'seekmemsize.c'" '(should have been 971 characters)' fi fi exit 0 # End of shell archive
--------------------------------------------------------------------- --------------------------------------------------------------------- Todd Pfaff provided the following code:
/* * mem.c - print physical memory installed in a machine * * $Author: kensmith $ * * $Date: 90/03/12 14:18:18 $ * * $Log: mem.c,v $ * Revision 1.2 90/03/12 14:18:18 kensmith * misc. cleanup * * Revision 1.1 90/02/09 21:43:41 kensmith * Initial revision * */
static char rcsid[] = "$Id: mem.c,v 1.2 90/03/12 14:18:18 kensmith Exp Locker: kensmith $";
#include <stdio.h> #include <sys/param.h> #include <sys/types.h> #include <sys/file.h> #include <nlist.h>
struct nlist nls[] = { { "_physmem" }, #define PHYSMEM 0 { "" }, };
int fd, physmem;
char *name; /* program name */ char *rindex();
main(argc, argv) int argc; char *argv[]; { if ((name = rindex(argv[0], '/')) == NULL) name = argv[0]; else name++; if (nlist("/vmunix", nls) < 0) { perror("nlist"); exit(1); } if ((fd = open("/dev/kmem", O_RDONLY)) <= 0) { perror("/dev/kmem"); exit(1); } if (nls[PHYSMEM].n_type == 0) { fprintf(stderr, "%s: physmem symbol not found\n", name); exit(1); } lseek(fd, nls[PHYSMEM].n_value, L_SET); read(fd, &physmem, sizeof(physmem)); printf("%d Kbytes of memory\n", ctob(physmem) / 1024); }
--------------------------------------------------------------------- ---------------------------------------------------------------------
Bob Shaw suggests the following perl script:
#!/usr/local/bin/perl # ######################################## # A simple PERL script to determine amount of PHYSICAL memory # on a Sun. # # Originally hacked by Bob Shaw with info from Larry Wall. # ######################################### # #------------------ $host = $ENV{'HOST'};
#------------------
$_ = `adb -k /vmunix /dev/mem </dev/null 2>&1`; if (/physmem\s+(.*)/) { print "Physical memory is ", int(hex($1) / 256 + 1), " megs for [$host]\n"; } else { die $_; }
--------------------------------------------------------------------- ---------------------------------------------------------------------
Thanks to: tim.cannon@amp.com harry@atmos.washington.edu david@capmkt.com rmills@ccd.harris.com rao@hobbes.crc.co Jacques.Beigbeder@ens.fr harishm@pcsdnfs1.eq.gs.com frank@darwin.sfbr.org symanski@gold.nosc.mi Ian_MacPhedran@engr.usask.ca strombrg@bingy.acs.uci.edu lccha@nb.rockwell.com jayl@lattice.com pom@netcom.com rwing!pat@ole.cdac.com rodney@cssc-syd.tansu.com.au klm@aule-tek.com nitkin@ptdcs2.intel.com Christian.Masopust@emndev.siemens.co.at bravo@ie.technion.ac.il hkatz@nucmed.med.nyu.edu Eckhard.Rueggeberg@ts.go.dlr.de peter@jrc.nl ballisti@ifh.ee.ethz.ch bern@penthesilea.uni-trier.d rmcm@ariel.ucs.unimelb.edu.au admin@di.uminho.pt B.T.Mccrone@dl.ac.uk kroeze@cs.utwente.nl ianh@fruitbat.uk D.Mitchell@dcs.shef.ac.uk Andrej.Misik@fmph.uniba.sk heiser@tif162.ed.ray.com rob.e.allan@hydro.on.ca dhb@ssd.ray.co jwelfeld@dasw.com ldk@lsci.com pln@egret1.stanford.edu Tim_Diebert.PARC@xerox.com wade@kegs.saic.com raoul@mit.edu danny@ews7.dseg.ti.com etnibsd!vsh@uunet.uu.net dave@scg8a.scg.hac.co todd@water.eng.mcmaster.ca bshaw@bobasun.spdc.ti.com moshel@taux01.nsc.com kiesel@vishnu.ueci.com
This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:09:06 CDT