determining size of physical memory

Paul Hite paul at prcrs.UUCP
Sat Dec 29 05:24:12 AEST 1990


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.

Well, I don't know of any "standard" way to do this.  But here are some HP-UX
solutions that you may be able to adapt to those other OS'es.  These have been
tested under HP-UX 3.1 and 7.0 on 9000 800's.

1)	HP-UX displays the physical memory at boot time.   Simply look at
	message.  These boot messages are saved in /usr/adm/messages.
	"grep mem /usr/adm/messages" yields:
		real mem = 67108864
		lockable mem = 51251200
		avail mem = 55265280
		using 1601 buffers containing 6709248 bytes of memory

2)	The support tape contains an unsupported program called "monitor".
	It can display memory size as well as many other useful data.

3)	The kernel has a value which indicates memory size.  You can display
	this by using something like:
		#include<stdio.h>
		#include<nlist.h>
		#include<fcntl.h>
		#define KERNEL "/hp-ux"
		main()
		{
		int fdkern;
		static struct nlist nl[2] = { { "physmem" } , { NULL } };
		int physmem;
		int  *address;

			nlist(KERNEL, nl);
			address = (int *)nl[0].n_value;
			fdkern = open("/dev/kmem", O_RDONLY);
			lseek(fdkern,(long) address,0);
			read(fdkern, (char *) &physmem, sizeof(physmem));
			printf("physmem = %d\n", physmem);
			physmem = physmem * 2 / 1024;
			printf("physical memory = %d Meg\n", physmem);
			exit(0);
		}


I hope this helps.

Paul Hite   PRC Realty Systems  McLean,Va   uunet!prcrs!paul    (703) 556-2243
        You can't tell which way the train went by studying its tracks.



More information about the Comp.unix.questions mailing list