0

I'm looking for a way to log the pid of process higher than a fixed value of cpu (ex 40%).

I tried with command like this : ps -eo pcpu,pid,user,args | sort -k 1,2 -r | head -10

But, first, it sorts by the first column of the output, not by the first value ... (1,20,2,3,31,4 ...), and strangly, the ps command doesn't show me the process higher than 20%! (I know there is some, by top).

Tks

3 Answers 3

0

reading man sort I see the -n option

-n, --numeric-sort

compare according to string numerical value

so I assume adding -n will sort numerically

ps -eo pcpu,pid,user,args | sort -k 1,2 -r -n | head -10
0

Maybe you want show the processes of all users, for which you can use:

ps -eoax
1
  • I just red a post that explain the value of cpu by 'ps' is not what I expected. The post #58539 quote the man pages : "CPU usage is currently expressed as the percentage of time spent running during the entire lifetime of a process.". So I don't have the same value with 'ps' as with 'top'.
    – VinceCore
    Aug 6, 2015 at 9:31
0

You can use top like this :

top -b -n1 | tail -n+8 | awk '$9 > 40 { print $1 }'

You must log in to answer this question.

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