How much memory am I using?

Nov
08
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.

Comment Icon

0 Comments

There are no comments yet. Why not be the first?

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <ul> <ol> <li> <dl> <dt> <dd> <img> <p>
  • You can use BBCode tags in the text. URLs will automatically be converted to links.
  • You can enable syntax highlighting of source code with the following tags: <pre>, <code>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.

Follow Me