On Solaris, how can I find out how much swap space a given process is occupying? Or even better, how can I list all running processes sorted by swap space usage?

I'm asking this particulary for Solaris. I do not have the top command available and neither prstat nor swap seem to be able to provide information about how much swap space a given process is using.


You can use the command:

pmap -S <pid>

to see all the memory statistics, including swap usage.

With little shell magic you can wrap it in a bash loop:

cd /proc
for i in *; do
    SWAP=`pmap -S $i | grep ^total | awk '{ print $3; }'`
    [ "xx$SWAP" != "xx" ] && echo "$SWAP bytes $i"
done | sort -n

Output is in bytes, in a format:

<number> bytes <pid>

I'm not sure if $3 matches the column you want, because it's the "Kbytes" and not "Swap" column.

In the Header it's the 3rd but not in the grep total (because of the blank in "total Kb"):

Address  Kbytes    Swap Mode Mapped File

total Kb  240576  235028`

for i in * ; do pmap -S $i 2> /dev/null | nawk -v PID=$i '$1 == "total" && $4 > 0 {print PID,"=>",$4,$2}' ; done |sort -rn -k 3,3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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