Is there a way to group similar processes when using tools like top/htop? Sometimes I just want to know what's eating my memory and some programs (browsers mostly) are using multiple processes, which makes it hard to read how much RAM they really use.
So far I came up only with something like that:
ps ax -o pmem,cmd | grep opera | grep -oE '^[ ]*[0-9.]+' | paste -sd+ - | bc
Best Answer
You can use
ps -C
to only display process information for a particular command name.e.g.
You can then use other
ps
options to extract just the data you are looking for. In particular,h
or--no-headers
to suppress the column headers, and-o pmem
to show the percentage of memory used by the process.That will give you a bunch of memory-usage percentages, one per line.
There are numerous methods for summing data like that, one of the methods I use frequently is to pipe it into xargs to convert it into one line with elements delimited by spaces, then into sed to convert spaces to
+
symbols, and then intobc
to perform the calculation. Your method of piping intopaste -sd+
works as well or arguably better than| xargs | sed
.Putting that all together, you get:
or
In other words, you can use
ps -C
instead of multiple greps if you just want data about one particular running program.NOTE: You can use multiple
-C
options on the same command line if you want info about more than one program at a time. e.g.