Skip navigation.
Sponsors
Recent comments
How much memory am I using?

How much memory am I using?

08
Nov
2007

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!

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!

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.

It'd be nice if you asked before taking stuff from my site. Contact me at webmaster [at] thingy - ma - jig . co . uk

This site was based on the Cobalt 2.0 Theme for phpBB written by Jakob Persson

Search
Weblinks

Add to Technorati Favorites

TGC Webring

CMS Drupal Showcase

Feedburner for ThingyMaJig

View Nicholas Thompson's profile on LinkedIn

IconBuffet

Twitter

bile-edge