How to view summaric memory usage of groups of commands (instead of processes)

You can use ps -C to only display process information for a particular command name.

e.g.

ps -C opera

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.

ps -C opera --no-headers -o pmem

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 into bc to perform the calculation. Your method of piping into paste -sd+ works as well or arguably better than | xargs | sed.

Putting that all together, you get:

ps -C opera --no-headers -o pmem | xargs | sed -e 's/ /+/g' | bc

or

ps -C opera --no-headers -o pmem | paste -sd+ | bc

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.

ps -C iceweasel -C chromium -C opera

Tags:

Process

Top