Snowcrash
Snowcrash

Reputation: 86057

How do you work out what's making up the total CPU% on Linux?

My fan is whirring on my Ubuntu laptop and htop is showing my CPU as maxed:

CPU

However, looking at the processes ordered by CPU it doesn't seem like too much is going on other than gjs at 41.3%.

Processes ordered by CPU

I'm assuming there are just a ton of gjs processes that are adding up to the rest of the CPU.

Is there anyway to work this out other than manually adding up the CPU%?

NAME="Ubuntu"
VERSION_ID="21.10"

Upvotes: 1

Views: 261

Answers (1)

AlexApps99
AlexApps99

Reputation: 3584

You can sum up CPU usage as shown here.

ps -eo pcpu,command --sort=-pcpu | grep gjs | awk '{sum+=$1} END {print sum}'

The solution they linked actually sums memory, not CPU usage (probably a bug they never caught), I've fixed it so it should work for you.

If you want to make a shell script to reuse, write this to cpusum for example:

ps -eo pcpu,command --sort=-pcpu | grep "$1" | awk '{sum+=$1} END {print sum}'

then make it executable: chmod +x cpusum, and run it ./cpusum gjs

Upvotes: 0

Related Questions