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.

In linux, how can I display memory usage of each process if i do a 'ps -ef'? I would like to the 'virtual memory', 'res memory', 'shared memory' of each progress. I can get that via 'top', but I want the same info in 'ps -ef ' so that I can pipe the output to 'grep {my process name}'.

Thank you.

share|improve this question

6 Answers 6

up vote 6 down vote accepted

Obtaining memory usage through ps is pretty unreliable. If you have a newer kernel it should support /proc/pid#/smaps which gives you some detailed information on each processes memory usage. Below is a pretty dirty and quick script to loop through each process that is open and grab the Size, Rss, Pss and Shared Clean/Dirty usage. Hopefully it can be useful in some kind of way.


for pid in $(ps -ef | awk '{print $2}'); do
    if [ -f /proc/$pid/smaps ]; then
            echo "* Mem usage for PID $pid"
            echo "-- Size:"
            cat /proc/$pid/smaps | grep -m 1 -e ^Size: | awk '{print $2}'
            echo "-- Rss:"
            cat /proc/$pid/smaps | grep -m 1 -e ^Rss: | awk '{print $2}'
            echo "-- Pss:"
            cat /proc/$pid/smaps | grep -m 1 -e ^Pss: | awk '{print $2}'
            echo "Shared Clean"
            cat /proc/$pid/smaps | grep -m 1 -e '^Shared_Clean:' | awk '{print $2}'
            echo "Shared Dirty"
            cat /proc/$pid/smaps | grep -m 1 -e '^Shared Dirty:' | awk '{print $2}'
share|improve this answer

ps ef -o command,vsize,rss,%mem,size

I could not find an option for shared memory, but I did find options for % of total physical memory and the amount of swapspace that would be needed to swap out the process. This and much more is documented in the man page for ps.

share|improve this answer
Linux accounts shared memory in the memory for each process, which can lead to bogus sums if you have lots of processes attached to one largish shared memory segment. top, ps, and similar programs are all affected by this in the same way. –  Peter Eisentraut Jan 29 '10 at 8:24
I know how shared memory works, but it appears ps cannot provide that information (or I was not able to find it in my ps documentation, at least). top or htop actually can show shared memory usage on a per process basis. –  Justin Smith Jan 29 '10 at 13:52

List processes by memory usage

ps -e -orss=,args= | sort -b -k1,1n

share|improve this answer
Use ps -e -orss=,pid=,args= | sort -b -k1,1n to include the process id –  Jacob Feb 16 '14 at 22:45

you can use

top -n 1
share|improve this answer

List processes by mem usage

command : ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS\

share|improve this answer

@user26528's answer doesn't quite calculate the memory correctly - you need the sum of the mappings in smaps, not just the top one. This script should do it:


for pid in $(ps -ef | awk '{print $2}'); do
    if [ -f /proc/$pid/smaps ]; then
        echo "* Mem usage for PID $pid"     
        rss=$(awk '/^Rss/ {i = i + $2} END {print i}' /proc/$pid/smaps)
        pss=$(awk '/^Pss/ {i = i + $2 + 0.5} END {print i}' /proc/$pid/smaps)
        sc=$(awk '/^Shared_Clean/ {i = i + $2} END {print i}' /proc/$pid/smaps)            
        sd=$(awk '/^Shared_Dirty/ {i = i + $2} END {print i}' /proc/$pid/smaps)
        pc=$(awk '/^Private_Clean/ {i = i + $2} END {print i}' /proc/$pid/smaps)
        pd=$(awk '/^Private_Dirty/ {i = i + $2} END {print i}' /proc/$pid/smaps)
        echo "-- Rss: $rss kB" 
        echo "-- Pss: $pss kB"
        echo "Shared Clean $sc kB"
        echo "Shared Dirty $sd kB"
        echo "Private $(($pd + $pc)) kB"
share|improve this answer

Your Answer


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.