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.