FYI - gotcha when using a nawk one liner to convert a processes RSS to MB

I used the following one liner (obtained from an old thread on this site) to look for RSS size of a process and convert it to Mb (I am using process nfsmapid as an example):

ps -eo rss,args | nawk 'END { print s/1024, "Mb" } /nfsmapid/ { s += $1 }'

I found that the RSS Mb displayed was always higher than if I took the RSS value and converted it manually to Mb.

What I found using this one liner was that the displayed value of $1 also included the RSS for the nawk process.

Using the one liner

ps -eo rss,args | nawk 'END { print s/1024, "Mb" } /nfsmapid/ { s += $1 }'
875.742 MB

Just displaying the RSS process

ps -eo rss,args | nawk '/nfsmapid/ {print $1/1024," " $2}'
874.461  /usr/lib/nfs/nfsmapid
1.28125  nawk

If you add 1.28125 to 874.461, the result is 875.742(25) MB

Using "+= $1" is great for collating the RSS of multiple processes with the same name

No doubt there is some way to stop this from occurring (I don't have time to investigate at the moment)

Try

 ps -eo rss,args | nawk '/[n]fsmapid/ {print $1/1024," " $2}' 
1 Like