Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!oliveb!sun!shukra!ram From: ram%shukra@Sun.COM (Renu Raman, Taco Bell Microsystems) Newsgroups: comp.unix.questions Subject: Re: Determining system memory Message-ID: <47738@sun.uucp> Date: 31 Mar 88 17:39:12 GMT References: <248@lxn.UUCP> Sender: news@sun.uucp Reply-To: ram@sun.UUCP (Renu Raman, Taco Bell Microsystems) Organization: Sun Microsystems, Mountain View Lines: 48 In article <248@lxn.UUCP> chris@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 > #include > > 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