1

I want to compare how much physical memory and CPU power google chrome and firefox use. So I tried to do this with htop which I usually use to keep track of my system resources and found out that I'm not able to draw a conclusion. I've read several threads but I'm still confused and this is why: When I filter with F4 for e.g. chrome, htop shows me dozens of tasks for which I don't know if they are threads or processes. AFAIK threads share the same address space but processes not. I can press F5 to have a tree view and there is one parent for all tasks. The assumption that the value of the parent task in the RES column gives the total memory and the value in the CPU% column the total CPU usage for this program regardless if it uses multiple processes or threads is apparently wrong. I found that out by doing this little experiment: I ran a python program I found which uses multiprocessing for some calculations. This is what I saw in htop: the parent value in the CPU% column shows 0 the whole time but there are 7 tasks which go up to 100% (my system has 4 physical cores with 2 threads each).

So could someone please explain what's going on and how can I check the total usage of physical memory and CPU for a program?

From what I've read it's not straightforward to determine the exact memory usage but the absolute value is not important in my case, I just need values I can use for comparison.

2 Answers 2

1

You may use this command:

pgrep -P $(pgrep chrome) | xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'

Or this one (change $9 to choose your column):

top -b -n1 | grep chrome | awk '{ SUM += $9} END { print SUM }'

More commands and advice can be found in:

0

psgrep gives an error:

$ pgrep -P $(pgrep chrome) | xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'
pgrep: only one pattern can be provided
Try `pgrep --help' for more information.
error: list of process IDs must follow -p

Usage:
ps [options]

Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.

For more details see ps(1).

I can see with htop the PID parent task and do this:

$ pgrep -P 1721 | xargs ps -o %mem,%cpu,cmd -p | awk '{memory+=$1;cpu+=$2} END {print memory,cpu}'
1.2 2.6

but 1.2% memory seems to be too low.

top doesn't count everything. E.g. with: $ top -b -n1 | grep freeplane | awk '{ SUM += $9} END { print SUM }' I'm getting 0 because it gets only this command: /usr/share/freeplane/freeplane.sh but not this one: /usr/sbin/java -Xmx512m -Dorg.freeplane

ps auxf seems to count everything and for chrome I'm getting with this:

$ ps auxf | grep chrome | awk '{ SUM += $4} END { print SUM }'
5.024G

which seems to be more realistic. Although if I measure the used memory with:

$ free -h

before and after I close Chrome I'm seeing 2.4Gi difference.

EDIT: I found ps_mem which makes really easy to check and compare memory usage of each application.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .