Determining system memory
Renu Raman, Taco Bell Microsystems
ram%shukra at Sun.COM
Fri Apr 1 03:39:12 AEST 1988
In article <248 at lxn.UUCP> chris at lxn.UUCP (Christopher D. Orr) writes:
>
>I have been trying to find a nice, clean way to determine system
>memory under SYS V 2.2. I have come up with two solutions to this
>problem. However, there must be a cleaner/faster way :-).
>
>Solution 1: The command 'wc -c /dev/mem' seems to work though it
> takes *FOREVER* on systems with large amounts on memory.
>
>Solution 2: The following 'C' program reports system memory much
> faster that Solution 1, but is still fairly slow:
> #include <stdio.h>
> #include <fcntl.h>
>
> extern int errno;
> static char BUF[32768];
>
> void main()
> {
> long int L;
> int M;
>
> M = open("/dev/mem",O_RDONLY);
> if (M < 0)
> {
> printf("Error: unable to open /dev/mem. errno=%d\n",errno);
> exit(1);
> }
>
> for (L=0;read(M,BUF,16384) == 16384 ;++L);
> printf("Memory Size: %ld\n",L * 16384);
> }
>
>Any other solutions are welcome (especially those that are faster :-)
>
>---
>Christopher D. Orr | US MAIL: Alcyone Inc.
>UUCP: vu-vlsi\ | Lanark Building
> ihnp4 - !lehi3b15!lxn!chris | Center Valley, PA 18034
> c11ux / | Voice: (215) 282-4525
Bezerkely and its derivatives have a kernel variable called _physmem.
Just get its location and read that variable from /dev/kmem.
_physmem is the total memory in expressed in clicks (system pages).
There must be an equivalent in Sys V. too. You may need nlist or
its variant for Sys. V.
Renu Raman
More information about the Comp.unix.questions
mailing list