Collection Values of "ps" command CPU column
How should I collect all values in $3 column of ps aux command.
ps aux |gawk ' { print $3 }' |
You posted a question AND the answer---what am I missing?????
|
I want get the total of CPU column
out put of ps command USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND db2inst1 7412 0.3 14.6 2102444 1220716 ? S 2008 1014:03 db2pfchr 0 db2inst1 7413 0.3 14.4 2102444 1198760 ? S 2008 827:52 db2pfchr 0 db2inst1 7414 0.2 14.3 2102444 1192684 ? S 2008 747:50 db2pfchr 0 db2inst1 7415 0.1 14.3 2102444 1191140 ? S 2008 490:54 db2pfchr 0 db2inst1 7416 0.0 14.2 2102460 1184528 ? S 2008 101:36 db2pclnr 0 db2inst1 7417 0.0 14.0 2102460 1171716 ? S 2008 101:03 db2pclnr 0 db2inst1 7418 0.0 14.1 2102460 1174420 ? S 2008 53:40 db2pclnr 0 db2inst1 7419 0.0 14.2 2102460 1187580 ? S 2008 99:30 db2pclnr 0 db2inst1 7420 0.0 14.2 2102460 1184460 ? S 2008 100:11 db2pclnr 0 db2inst1 7421 0.0 14.2 2102460 1186876 ? S 2008 100:45 db2pclnr 0 db2inst1 7422 0.0 14.2 2102460 1182888 ? S 2008 100:48 db2pclnr 0 |
Take a look at "top". It gives the total CPU usage and the usage for each process. On my machine, the total DOES NOT match the sum of the various processes. My interpretation is that the CPU usage reported for each process is the average over a certain window. 2 processes, however, will not be using the cpu at the same time, so the total will be less than the sum of the averages.
I don't know of a command to sum up a series of number, but keep in mind that the output of something like ps is rounded--eg all those "0.0"s may really be some finite value. |
You could try this but as said I think the result is pretty useless in the real world.
Code:
ps aux | awk 'BEGIN {total=0} |
How should collect total CPU average at a given time ?
|
Quote:
|
In top out how can get the CPU usage in to one value(can I add all values in CPU raw)
# top top - 01:24:29 up 22:00, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 74 total, 1 running, 73 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.8%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1025716k total, 359408k used, 666308k free, 135128k buffers Swap: 2031608k total, 0k used, 2031608k free, 176960k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 15 0 2060 636 544 S 0.0 0.1 0:01.80 init 2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0 3 root 39 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 |
In top out how can get the CPU usage in to one value(can I add all values in CPU raw)
# top top - 01:24:29 up 22:00, 1 user, load average: 0.00, 0.00, 0.00 Tasks: 74 total, 1 running, 73 sleeping, 0 stopped, 0 zombie Cpu(s): 0.0%us, 0.0%sy, 0.0%ni, 99.8%id, 0.1%wa, 0.0%hi, 0.0%si, 0.0%st Mem: 1025716k total, 359408k used, 666308k free, 135128k buffers Swap: 2031608k total, 0k used, 2031608k free, 176960k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1 root 15 0 2060 636 544 S 0.0 0.1 0:01.80 init 2 root RT -5 0 0 0 S 0.0 0.0 0:00.00 migration/0 3 root 39 19 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root RT -5 0 0 0 S 0.0 0.0 0:00.00 watchdog/0 |
You might want to look at the -b and -n options to top. You have to decide which CPU values you want eg %us (user)
|
Sorry--I missed something. I thought that "top" gave the desired total(s). What does "man top" tell you?
|
Try :
Code:
man sar To get the total from top : Code:
top -b -n1 | awk ' BEGIN { total=0} { total+=$9} END {print total}' |
top -b -n1 | awk ' BEGIN { total=0} { total+=$9} END {print total}'
Please be kind enough to explain how this command ex cutting ? |
Code:
{ ps aux | gawk ' { print $3 }' | grep -v CPU | sed '2,$ s/$/ +/'; echo p; } | dc Mine probably isn't the best. What it does is removes the column heading first, then adds a + sign to the second thru last lines and feeds it to the dc program, which performs all of the additions. The p tells it to print the result when it's done. ta0kira PS If you can get a list with one number per line and only numbers, the underlined part will total it for you. |
All times are GMT -5. The time now is 06:28 AM. |