I've tried sending this about 5 times, and each time it seems to have
gone to /dev/null/.
Most operating systems (Linux, Solaris, AIX, Tru64, HP-UX, IRIX being
examples) support the sysconf() function to get all sorts of
long sysconf(int name);
Most OS's (IRIX, Tru64, HP-UX being exceptions) support a method
might expect to be able to determine the amount of RAM in the system
with sysconf(), but whilst it works *exactly* on some systems, it is
only *approximate* on others.
The size of memory pages (in bytes) can be found -
and the number of memory pages too - sysconf(_SC_PHYS_PAGES);
Multiplying the two together (taking care not to overflow), gives the
number of bytes of RAM the computer has - on some systems anyway.
Dividing by the number of bytes in a Mb (1048576), gives the RAM in Mb
- or so I thought. Is this not right ?????
This works exactly on Solaris 9 and exactly under AIX 5.2 too. But
under Linux it says 2017 on a system with 2 Gb, and 3886 Mb on a
system with 4 Gb.
Does anyone know if these calls are supposed to work in the way I
think ? Are they defined by POSIX, and if so how ? It seems odd that
Solaris, Linux and AIX all support them, but Tru64, IRIX and HPUX
don't. HP-UX 11 has _SC_PAGE_SIZE, but not _SC_PHYS_PAGES.
The linux man page (for my Redhat system - 6.2 I think) says:
The size of a page (in bytes).
The number of pages of physical memory. (Note that it is
possible for the product of this value and the value of _SC_PAGE_SIZE
So the Linux man page is suggesting one might multiply
sysconf(_SC_PAGE_SIZE)*sysconf(_SC_PHYS_PAGES), so the man page
clearly thinks there is some use to doing this.
Any thoughts ????
Dr. David Kirkby,
Senior Research Fellow,
Department of Medical Physics,
University College London,
11-20 Capper St, London, WC1E 6JA.
Author of 'atlc' http://atlc.sourceforge.net/