ThingyMaJig

Thingy Ma Jig is the blog of Nicholas Thompson and contains any useful tips, sites and general blog-stuff which are considered interesting or handy!

Connect

LinkedIn GitHub

Topics

announcement 25 apache 3 Apple 1 bash 8 code 7 cool 30 Days Out 8 Dark Basic Pro 4 design 12 doctor who 1 Drupal 74 E4600 1 EOS 400D 3 firefox 2 Flickr 3 free 21 games 5 geek 38 git 2 GreaseMonkey 1 hardware 7 Homebrew 1 How to 37 humour 5 iphone 1 javascript 1 jquery 1 K800i 6 k850i 4 lighttpd 3 linux 33 mac 9 miscellaneous 4 mobile phone 9 music 4 mysql 8 n73 1 n95 1 New Relic 1 Ogre3D 1 OS X 2 performance 3 photos 10 programming 40 Quicksilver 1 review 19 security 3 SEO 6 software 12 svn 2 technology 4 tip 7 tips 10 tv 3 video 3 vim 7 webdev 2 websites 33 wii 1 windows 1 YADS 10

How much memory am I using?

Posted on 08 November 2007 in
programming linux How to geek cool

Following on from my previous post about how to check how many apache processes are running - I recently wanted to find out exactly how much memory my applications where using… So I did a little research and found a few new and useful commands!

[adsense:468x60:4496506397]

ps haxo 'size' | (tr '\n' +; echo 0) | bc

You will recognise the ps command from the previous post, the extra 'h' option tells it to hide the header (You cant do 'SZ + 5 + 6'!) and the new tr command translate or delete characters (from the manual pages). So this strips out all new lines and puts a '+' after each number. The reason we need to echo 0 onto the end is because if we didn't we would end up with 1+2+3+. The bc command is a basic calculator and will just add up whatever numbers it gets!

[adsense:468x60:4496506397]

So, ps produces a column of numbers, tr concatenates each newline-separated number with a '+' symbol. A zero is added to the end of the string and finally the entire string of numbers are parsed using the bc command.

The result is a single number which represents the number of kilobytes currently in use by your applications.