2

I need to display processes that use more than 30% CPU via command top. How can I do it?

2 Answers 2

3

You can use Filtering within top with o (small 'o'). After pressing you see a line for your command (something like add filter #1 (ignoring case) as: [!]FLD?VAL. Just write down, what you want to see: %CPU>30.0. And hit Enter. Tadah!

More details can be found with FILTERING in a Window section of man top


Older part of the post:

ps -eo %cpu,args | awk '$1 >= 30 {print}'

ps command list all processes with their cpu usage (in percent) and args (see man ps for more options under STANDARD FORMAT SPECIFIERS section) and awk than print only these with first column >= 30.

4
  • d'oh, I missed 'via top command' suffix..
    – stderr
    Jul 13, 2016 at 10:36
  • ... so I added the right answer :)
    – stderr
    Jul 13, 2016 at 10:48
  • Note that the percent output here is a percent of 1 CPU. So, if the command shows a process is taking 52% of the CPU, that's 52% of 1 CPU. Assuming you have 8 CPUs, that means the overall percent of your processing power taken by that process is equal to 52/(8*100) = 0.065 = 6.5%. Jan 18, 2022 at 22:07
  • To see instantaneous overall CPU usage, see my answer here: Stack Overflow: How to get overall CPU usage (e.g. 57%) on Linux Jan 18, 2022 at 22:09
0

For Rhel, run top command. Then press shift + f and then press k followed by Enter. This will sort the output by CPU usage.

4
  • Why only RHEL? This applies to every GNU/Linux system.
    – schaiba
    Jul 13, 2016 at 11:00
  • Because shift + f doesn't work in SunOS. Jul 13, 2016 at 11:05
  • I said it applies to every GNU/Linux system. Linux != SunOS. There are indeed differences between *nixes but top on every Linux distro is the same.
    – schaiba
    Jul 13, 2016 at 11:07
  • Apology, I missed that part. Jul 13, 2016 at 11:12

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.