[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cobalt-developers] raq4 memory problem...
- Subject: Re: [cobalt-developers] raq4 memory problem...
- From: Chris (CJ) Johnson <cj.johnson@xxxxxxx>
- Date: Tue Aug 20 11:49:00 2002
- List-id: Discussion Forum for developers on Sun Cobalt Networks products <cobalt-developers.list.cobalt.com>
> physical=`grep Mem: /proc/meminfo | awk '{print $2}'`
> used=`grep Mem: /proc/meminfo | awk '{print $3}'`
> buffers=`grep Mem: /proc/meminfo | awk '{print $6}'`
> cache=`grep Mem: /proc/meminfo | awk '{print $7}'`
> swapused=`grep Swap: /proc/meminfo | awk '{print $3}'`
> echo $(( $physical - $used + $cache + $buffers - $swapused ))
Ack gag phft! After seeing the above _too_ many times
in my inbox I am forced to express my disgust.
How about
awk ' /Mem:/ { memfree = $2 - $3 + $6 + $7 }
/Swap:/ { swap = $3 }
END { print memfree - swap } ' /proc/meminfo
Why use one process when 11 can do the trick, I suppose.
At least someone posted an optimization that cut it to
10 by eliminating the 'bc'. Woopie!
Back when I was raised, (4 MHz cpu, yada yada yada) :-)
As a general note : awk and perl are actually quite good
at string manipulation. Anytime you write code that does
grep ... | awk
or
grep ... | perl
you should go get another cup of your favorite caffeinated
beverage, and try again.
This rant brought to you by Mr "Too Much Coffee Man".
cj*