0

I created a command to show me what processes eat RAM

alias psmem='ps -eo user,pid,pcpu,pmem,args --sort -pmem --columns $(tput cols) | head -25'

However, the output typically looks like this:

USER         PID %CPU %MEM COMMAND
barafu      2113  5.8  2.4 /usr/lib/chromium/chromium --type=renderer --enable-oop-rasterization --field-trial-handle=
barafu      1489  4.6  1.8 /usr/lib/chromium/chromium --type=gpu-process --field-trial-handle= --enable-gpu-raster
barafu      2765  0.6  1.8 /usr/lib/chromium/chromium --type=renderer --enable-oop-rasterization --field-trial-handle=
barafu      1460  1.7  1.7 /usr/lib/chromium/chromium --password-store=basic --ignore-gpu-blacklist --enable-gpu-rasterization --enable-zero-copy --enable-oop-
barafu      1326  2.0  1.5 cinnamon --replace
barafu      1594  0.1  1.3 /usr/lib/chromium/chromium --type=renderer --enable-oop-rasterization --field-trial-handle=

Question: Is there a way to tell ps to combine all those chromiums into one entry?

2

ps’s output granurality is limited to individual processes or threads, it can’t merge processes. You’ll have to post-process its output.

Something like this should get you started:

ps -eo user=,pid=,pcpu=,pmem=,args= --sort -pmem --columns $(tput cols) |
awk '{ cpu[$1][$5] += $3; mem[$1][$5] += $4 } END { for (user in cpu) { for (cmd in cpu[user]) { print user, cpu[user][cmd], mem[user][cmd], cmd } } }' |
sort -k3,3nr | head -n 25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.