Finding memory info

Michael L Torrie torriem at
Thu Jun 21 10:12:11 MDT 2007

On Thu, 2007-06-21 at 09:33 -0600, Derek Davis wrote:
> 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?

/proc/meminfo does not include video memory, unless the video card is
using RAM instead of VRAM.  Either way it's accurate.  It reflects the
amount of RAM physically installed.

Rather than parsing lshw, why not take a look at how lshw gathers the
information?  Maybe lshw could be modified to alter it's output format,


More information about the PLUG mailing list