Detecting amount of memory?

Patrick Lists ks-list at puzzled.xs4all.nl
Tue Dec 21 13:29:41 UTC 2010


On 12/21/2010 02:05 PM, Callahan, Tom wrote:
> The trick is, 6123716 KB isn't actually 6GB, it's slightly less. That's why
> you are getting the results you are getting.
> 
> http://www.google.com/search?q=6123716KB+in+GB
> 
> 
> On 12/21/10 7:18 AM, "Patrick Lists" <ks-list at puzzled.xs4all.nl> wrote:
> 
>> 6123716

Yup see that now. Still I wonder why free says MemTotal is less than 6GB
when the box has 6GB. That's the interesting part. I seem to be missing
something. Where did those last few bytes go? Or could this be a case of
GB versus GiB.

Strangely this awk line does work but I have no awk foo so this is like
dark arts to me (line 2,3,4 should all be on one line):

mem=$(free|grep Mem|awk '{print$2}')
echo "$mem" | awk '{ n = $0; sub(/[0-9]+(.[0-9]+)?/, ""); split(n, a,
$0); n=a[1]; if ($0 == "G" || $0 == "") { n *= 1024 }; if (/^kB?/) { n
/= 1024 }; printf "%d\n", n }'
# Intentionally rounded to an integer

Regards,
Patrick





More information about the Kickstart-list mailing list