Determining system memory

Christopher D. Orr chris at lxn.UUCP
Thu Mar 31 06:18:57 AEST 1988


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



More information about the Comp.unix.questions mailing list