How much memory am I using?

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.

Comment Icon

0 Comments

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

Add new comment

Filtered HTML

  • 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: <code>, <pre>, <bash>, <css>, <html>, <js>, <jquery>, <mysql>, <php>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.