Group processes with ps

I want to use ps on my desktop via geektools to find out which processes use what. Currently, my team:

ps -amcwwwxo "command %mem %cpu" | grep -v grep | head -13

The problem with this, since I'm using chrome, the Google Chrome He process takes up most of 13 lines of display.

Is there a way to summarize the use of mem and cpu of all processes with the same name? Either via ps, or using another command.

+3
source share
4 answers

You can use a combination of awkand 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
)
+3
source

Looking for the same thing, I figured it out

ps aux | awk '{arr[$1]+=$4}; END {for (i in arr) {print i,arr[i]}}' | sort -k2

, mem, (1, $1), , $1 $4

  • $1 - : ()
  • $4 - :% mem ( )

, .

+1

top cpu group :

sudo ps aux | awk '{arr[$11]+=$3}; END {for (i in arr) {print arr[i],i}}' | sort -k1nr | head -n 10
+1

, /​​/ script, . Google Chrome Helper - , , script, Chrome (, ..), .

0

All Articles