Finding memory info

Derek Davis derek.davis at
Thu Jun 21 09:33:48 MDT 2007

I'm trying to gather memory information about various linux machines
programmatically.   I have a client who has several different types of
machines, so he really gives my code a workout.  In order to get the
amount of memory, I am using lshw because it gives the number of
memory banks as well.  However, it often reports it in slightly
different formats on different machines, making my code keep breaking.
 I'm trying to make it as generic as possible, but never know when a
new case will arise that I missed.

How would you accomplish this?  Is parsing lshw my best bet?  Should I
just get the number of banks from lshw, and the amount of memory from
/proc/meminfo?  Will /proc/meminfo be inaccurate if some of the memory
is used by onboard video, or something like that?

Derek M Davis                                derek.davis at
"Man has no choice about his need for self-esteem.
 He can only choose by what standard to gauge it."

More information about the PLUG mailing list