This is a great bit of awk that the Awk God known as Gary (Le Minkey) Crowe wrote for me to find out how much memory each of my zLinux processes was eating. I’ve just formatted slightly and sorted the output.

If you add up all the values output from this, it should equal approx. used memory less buffers and cache.

#!/bin/bash
 
# Program to find the highest value of each reported process from
# the ps ao command.
 
ps axo rss,comm | sed -n '2,$p'| awk '
{
if ( $1+0 > high[$2] )
high[$2]=$1
}
END { for (value in high)
printf "%-20s : %g",value,high[value] }'|grep -v ": 0" | sort -nkr

I run this with the watch command to monitor in realtime.

In AIX, I have modified to run as follows: –

ps aux|grep -v USER|awk '{print $6,$12}' | awk '
{
if ( $1+0 > high[$2] )
high[$2]=$1
}
END { for (value in high)
printf "%-20s : %g\n",value,high[value] }' | sort -k3r

About troyski

I'm a freelance UNIX engineer working in the UK. I'm married to Tina and between us we have six children. I'm a bit of an Apple fan boy, and all the Windows machines in the house are a thing of the past now.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post navigation