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
)