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!

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.

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.