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

Paul Haldane
  • 4,517
  • 1
  • 21
  • 32
VinceCore
  • 31
  • 4

3 Answers3

0

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

ps -eoax
HBruijn
  • 77,029
  • 24
  • 135
  • 201
  • 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 06 '15 at 09:31
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
gwillie
  • 231
  • 1
  • 9
0

You can use top like this :

top -b -n1 | tail -n+8 | awk '$9 > 40 { print $1 }'
Sylvain Firmery
  • 331
  • 1
  • 4