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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FYI - gotcha when using a nawk one liner to convert a processes RSS to MB
# 1  
Old 05-20-2015
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):
Code:
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
Code:
ps -eo rss,args | nawk 'END { print s/1024, "Mb" } /nfsmapid/ { s += $1 }'
875.742 MB

Just displaying the RSS process
Code:
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)

Last edited by Scott; 05-20-2015 at 03:01 AM.. Reason: Please use code tags
# 2  
Old 05-20-2015
Try
Code:
 ps -eo rss,args | nawk '/[n]fsmapid/ {print $1/1024," " $2}'

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Solaris

RSS of prstat vs RSS of PS

Hi, When I sum the RSS number in the ps command for a specific user and compare it with the RSS values of the prstat command of the same user - there is a big difference. Server details: Solaris 10 5/09 s10s_u7wos_08 SPARC prstat output: NPROC USERNAME SWAP RSS MEMORY TIME ... (2 Replies)
Discussion started by: amitlib
2 Replies

2. Shell Programming and Scripting

Nawk Problem - nawk out of space in tostring on

Hi.. i am running nawk scripts on solaris system to get records of file1 not in file2 and find duplicate records in a while with the following scripts -compare nawk 'NR==FNR{a++;next;} !a {print"line"FNR $0}' file1 file2duplicate - nawk '{a++}END{for(i in a){if(a-1)print i,a}}' file1in the middle... (12 Replies)
Discussion started by: Abhiraj Singh
12 Replies

3. Shell Programming and Scripting

Nawk One Liner to Count Field Combinations

I have text files, fields separated by commas, and there are 115 fields. I need to use nawk to look at each line, if field $4==10, then count how many times the combination of field $5 and field $11 occur in the file. I tried the following: nawk -F, '{if($4==10){tg++;cd++,tgcd++}}END{for(i in... (3 Replies)
Discussion started by: he204035
3 Replies

4. Shell Programming and Scripting

Perl one-liner convert to script format problem asking

Input_file_1: ABC1 DEF11 ABC3 DEF7 ABC7 DEF36 Input_file_2: DEF7 light 23 DEF11 over 2 DEF11 over 1 DEF17 blue 0 Perl one-liner that join two input file based on columns sharing a value (In this example, column 2 in Input_file_1 and column 1 in... (3 Replies)
Discussion started by: perl_beginner
3 Replies

5. Shell Programming and Scripting

Using awk or nawk to convert epoch time to date format

Looking for some help and usually when I do a search this site comes up. Hopefully someone can give me a little direction as to how to use one of these two commands to achieve what I'm trying to do. What am I trying to do? I need to take the time value in epoch format returned from the... (5 Replies)
Discussion started by: minigts
5 Replies

6. Shell Programming and Scripting

Search & Replace regex Perl one liner to AWK one liner

Thanks for giving your time and effort to answer questions and helping newbies like me understand awk. I have a huge file, millions of lines, so perl takes quite a bit of time, I'd like to convert these perl one liners to awk. Basically I'd like all lines with ISA sandwiched between... (9 Replies)
Discussion started by: verge
9 Replies

7. Red Hat

FYI, no ext2online on 5.5, just use resize2fs

FYI On redhat enterprise 5.5, no more ext2online, just use below # resize2fs /dev/uservg/xxxxxxx resize2fs 1.39 (29-May-2006) Filesystem at /dev/uservg/xxxxxxxxx is mounted on /xxxxxxx; on-line resizing required................................. It will increase the size on the fly... (0 Replies)
Discussion started by: itik
0 Replies

8. Shell Programming and Scripting

how to access values of awk/nawk variables outside the awk/nawk block?

i'm new to shell scripting and have a problem please help me in the script i have a nawk block which has a variable count nawk{ . . . count=count+1 print count } now i want to access the value of the count variable outside the awk block,like.. s=`expr count / m` (m is... (5 Replies)
Discussion started by: saniya
5 Replies
Login or Register to Ask a Question