LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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, 12:45 PM   #1
grob115
Member
 
Registered: Oct 2005
Posts: 540

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, 12:49 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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 12:52 PM.
 
Old 04-29-2010, 12:55 PM   #3
grob115
Member
 
Registered: Oct 2005
Posts: 540

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, 01:03 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738Reputation: 738
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, 01:44 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:36 PM
MD5 sum Pedroski Linux - Software 4 12-08-2009 03:17 PM
Getting SUM in Bash thewebbie Programming 1 05-20-2009 12:42 PM
How to disable the sum check abd_bela Debian 2 01-15-2009 06:56 PM
Check sum emmanuelmathew Linux - Newbie 2 02-12-2003 02:14 AM


All times are GMT -5. The time now is 12:54 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration