Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have tried top and PS command but i am not able to find the RAM used by each process.

top command says that 240MB RAM used but the Memory shows 0% for all the processes, same with ps. i want to know which process consumes all 240MB RAM.

Is there any command which / script which can sort the running process in oder of increasing RAM usage so that i can see. Also i find it very hard to read bytes and KB. Is there any to way to chnage those units to MB

Please help

share|improve this question
    
What does free -m say? –  Turbo J Jul 10 '11 at 20:18
add comment

3 Answers

ps -eo rss,pid,user,command --sort -size | \
awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }' | \
egrep -v 0.00

prints:

     6.65 Mb /usr/sbin/mysqld
     0.75 Mb rsyslogd -c4
    38.59 Mb /usr/sbin/apache2 -k start
    37.95 Mb /usr/sbin/apache2 -k start
    34.38 Mb /usr/sbin/apache2 -k start
    33.35 Mb /usr/sbin/apache2 -k start
    31.43 Mb /usr/sbin/apache2 -k start
     2.38 Mb /usr/bin/python /usr/bin/fail2ban-server -b -s /var/run/fail2ban/fail2ban.sock
     0.61 Mb /usr/sbin/nova-agent -q -p /var/run/nova-agent.pid -o /var/log/nova-agent.log -l info /usr/share/nova-agent/nova-agent.py
     3.00 Mb /usr/sbin/apache2 -k start
     1.71 Mb sshd: root@notty
     0.36 Mb sshd: root@pts/0
     1.10 Mb ps -eo rss,pid,user,command --sort -size
     1.40 Mb /usr/lib/openssh/sftp-server
     0.59 Mb /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 103:105
     0.08 Mb /usr/sbin/sshd -D
     0.21 Mb /sbin/init
     1.18 Mb -bash
     0.28 Mb cron
     0.88 Mb qmgr -l -t fifo -u

Keep in mind that free and top will show "cached" memory so you won't be able to tell how much is actually used and free. It's technically free to the system, though it might have to dump the cache to use it. I find free not so useful, and top only slightly more useful (plus top usually consumes any free RAM I have lol).

share|improve this answer
add comment

Run "System Monitor" there is a processes tab that can be sorted by memory usage. I am not familiar with centos, it comes preinstalled on Ubuntu, which I use.

share|improve this answer
add comment

If you just do a top, it will display memory usage as a percentage of total system memory. If everything is showing 0, then nothing is using a significant percentage of memory. This is actually not uncommon. Consider if you have a server with 8 gigs of ram, 1% is 80 megs. It is entirely possible that 240 megs is made up of a bunch of things that use less than 40 megs a piece. So percentages won't help you.

If you do a

top -M

it should spit out actual memory usage in whatever applicable units.

share|improve this answer
    
i am using VPS so think it is showing the total memory but in actual i have 768MB RAM , so % is not working for me –  Moorage Jul 11 '11 at 2:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.