LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-29-2010, 11:45 AM   #1
grob115
Member
 
Registered: Oct 2005
Posts: 542

Rep: Reputation: 32
awk's sum not working?


Hello,

Trying to get a total of the memory consumption for the httpd process. The 10th column is displaying the % used. Just wondering how the summed value is able to get over 100%?

[root@vps htdocs]# /usr/bin/top -n 1 -b | grep httpd | awk '{SUM += $10} END {print SUM}' 151.9
[root@vps htdocs]# /usr/bin/top -n 1 -b | grep httpd | awk '{SUM += $10} END {print SUM}'
148.1
[root@vps htdocs]# /usr/bin/top -n 1 -b | grep httpd | awk '{SUM += $10} END {print SUM}'
104.6
[root@vps htdocs]# /usr/bin/top -n 1 -b | grep httpd | awk '{SUM += $10} END {print SUM}'
96.8
 
Old 04-29-2010, 11:49 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I don't have httpd on my system, so I did this:
Code:
root@mystical mherring]# /usr/bin/top -n 1 -b | grep udevd
 1105 root      16  -4  6500 1160  412 S    0  0.0   0:00.04 udevd                                                                                            
16299 root      18  -2  6216  896  432 S    0  0.0   0:00.00 udevd                                                                                            
16300 root      18  -2  6496 1108  364 S    0  0.0   0:00.00 udevd                                                                                            
[root@mystical mherring]#
How is your AWK syntax supposed to operate on this output?

EDIT: OK, I see that you are incrementing SUB with the value of field $10. I wonder if it adds several instances? Try watching top to see what the values are on each refresh.

Last edited by pixellany; 04-29-2010 at 11:52 AM.
 
Old 04-29-2010, 11:55 AM   #3
grob115
Member
 
Registered: Oct 2005
Posts: 542

Original Poster
Rep: Reputation: 32
Mine is exactly the same as yours. It's supposed to add the column before the one that shows the up time. Yours is showing 0.0 for all of them so these processes that you used are very small in memory usage.

Sample of my top output. Trying to add the %MEM column with the awk.

top - 10:30:04 up 652 days, 17:03, 2 users, load average: 50.00, 20.17, 8.26
Tasks: 91 total, 58 running, 29 sleeping, 0 stopped, 4 zombie
Cpu(s): 48.3% us, 6.6% sy, 0.0% ni, 41.8% id, 3.3% wa, 0.0% hi, 0.0% si
Mem: 262144k total, 256860k used, 5284k free, 0k buffers
Swap: 0k total, 0k used, 0k free, 0k cached

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
5435 apache 16 0 39132 14m 3744 S 1.9 5.8 0:00.36 httpd
5532 apache 16 0 39460 14m 4044 R 1.9 5.8 0:02.08 httpd
5593 apache 16 0 38412 14m 3784 R 1.9 5.5 0:00.69 httpd
 
Old 04-29-2010, 12:03 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
I tried "top" and saw that X was averaging about 15% cpu usage. I then did "top|grep X" and X was averaging 2% cpu.

Conclusion: I'm not sure if I would trust top piped into grep. More research needed.

going back to the original problem: What is the point of summing the CPU usage values?
 
Old 04-29-2010, 12:44 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Just for a sanity check:
Code:
top -b -n 1| awk '/httpd/{print $10": "$0;sum+=$10}END{print sum}'
Seems quite right on my machine - changes if I put a bit of load on
apache, e.g., fire up some PHP based site(s).


Cheers,
Tink
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sum of output phsythax Linux - Newbie 12 12-16-2009 06:36 PM
MD5 sum Pedroski Linux - Software 4 12-08-2009 02:17 PM
Getting SUM in Bash thewebbie Programming 1 05-20-2009 11:42 AM
How to disable the sum check abd_bela Debian 2 01-15-2009 05:56 PM
Check sum emmanuelmathew Linux - Newbie 2 02-12-2003 01:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration