I want to use ps on my desktop through geektools to see what processes are using what.
Currently my command is:
ps -amcwwwxo "command %mem %cpu" | grep -v grep | head -13
The problem with this, is seeing as I'm using chrome, the process "Google Chrome He" takes up most of the 13 display lines.
Is there any way to sum together the mem and cpu usage of all processes of the same name? Either via ps or piping it through another command.
You may use a combination of awk
and sort
:
(
printf "%-20s %-8s %-8s\n" "COMMAND" "%MEM" "%CPU"
/bin/ps -amcwwwxo "command %mem %cpu" |
/usr/bin/awk -F" " '
BEGIN {
idx=0
format="%-20s /%-8s/ %-8s\n"
}
{
idx = idx + 1
col1=$0
col2=$(NF-1)
col3=$NF
sub(/[[:space:]]+[^ ]+[[:space:]]+[^ ]+[[:space:]]*$/,"", col1)
a[idx]=col1
b[col1]+=col2
c[col1]+=col3
}
END {
for(i=2; i<=idx; i++)
{
if (a[i] in b)
{
printf format, a[i], b[a[i]], c[a[i]]
delete b[a[i]]
}
}
}
' |
/usr/bin/sort -rn -t '/' -k 2,2 | /usr/bin/tr -d '/' | /usr/bin/head -n 15
)
It does not exist, you should write your own code/command/script to do it. Because all Google Chrome Helper processes are distinct processes, maybe you can write a script which computes all Chrome processes (helper, plug-in hosts etc.) using parent process id.
Looking for the same, I figured out this
ps aux | awk '{arr[$1]+=$4}; END {for (i in arr) {print i,arr[i]}}' | sort -k2
to print processes ordered by mem, grouped by user (column1, the $1), you can group by other things, and sum other things, changing $1 and $4
I was happy to find the solution, just wanted to share.
top cpu group by command line:
sudo ps aux | awk '{arr[$11]+=$3}; END {for (i in arr) {print arr[i],i}}' | sort -k1nr | head -n 10