Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!wuarchive!uunet!prcrs!paul From: paul@prcrs.UUCP (Paul Hite) Newsgroups: comp.unix.questions Subject: Re: determining size of physical memory Keywords: core, physical memory, size of core Message-ID: <1368@prcrs.UUCP> Date: 28 Dec 90 18:24:12 GMT References: <1990Dec27.202715.27688@Neon.Stanford.EDU> Organization: PRC Realty Systems, McLean, VA Lines: 52 In article <1990Dec27.202715.27688@Neon.Stanford.EDU>, hitt@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 #include #include #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.