How can I determine how much RAM my system has? Updated: 06/14/02


From SAM
========
1) goto Performance Monitors -> System Properties -> Memory
2) check Clock Frequency: value

From the command-line
=====================
If you are root, you can use adb to query the kernel:

# echo "memory_installed_in_machine/D" | adb -k /stand/vmunix /dev/mem
| \
tail -1 | awk '$2 > 0 { print $2 / 256 }'

Or if /etc/dmesg is still current, you can grep it:

$ /etc/dmesg | grep "real mem" | tail -1 | \
awk '$4 > 0 { print $4 / 1048576 }'

A few more methods that can be used (as root only):

o As of 10.x, the following SAM command will show memory in MB:
# /usr/sam/lbin/getmem
However, getmem reportedly does not work on systems with >512 MB of
RAM,
and it is not supported by HP.

o It's painfully slow, but the following cute method will also give the
total MB:
# expr `wc -c /dev/mem | cut -d' ' -f1` / 1048576

o The following creative method suggested by Siem Korteweg
<siem@xs4all.nl> prints the size in MB but works only on 10.x:
# dd if=/dev/mem of=/dev/null bs=1024k 2>&1 | grep in | cut -d+ -f1

Programmatically
================
Here is a short program that will print the system's RAM size (can be run
by any user):

/* mem.c - To compile: cc +DAportable -o mem mem.c */
#include <errno.h>
#include <stdio.h>
#include <sys/param.h>
#include <sys/pstat.h>
#define BYTES_PER_MB 1048576
main()
{
struct pst_static pst;
union pstun pu;

pu.pst_static = &pst;
if ( pstat( PSTAT_STATIC, pu, (size_t)sizeof(pst), (size_t)0, 0 ) != -1
) {
printf( "Physical RAM = %ld MB\n",
(long)( (double)pst.physical_memory * pst.page_size / BYTES_PER_MB
) );
exit( 0 );
} else {
perror("pstat_getstatic");
exit( errno );
}
}



UNIXguide.net
Suggest a Site