Output high CPU processes using bash shell

1

I am trying to monitor my CentOS processes using top command to see if there are any processes where CPU usage is greater than X%, below is the command I am using to see if any processes CPU usage is greater than 10%.

top | awk '{if (NF == 14) {
  if ( int($10) >= 10 ) { print $0; system("ps -ef | grep " $13); }
}}' >> top.txt

It seems like the above command will miss some results. While the above command is running, I open another session and execute top command. I have noticed that sometimes when I saw some processes CPU usage are greater than 10%, but the results are not captured via the command above.

Not sure if there are better ways, or I the above script is wrong.

Many thanks!

forestclown

Posted 2012-03-27T06:36:40.000

Reputation: 461

Answers

3

The top command is not the best choice for parsing data. Try to use sar instead (if not installed by default, run yum install sysstat), or iostat -c.

Eran Ben-Natan

Posted 2012-03-27T06:36:40.000

Reputation: 334