Solved

log processes with high CPU usage?

Posted on 2013-06-11
5
285 Views
Last Modified: 2013-06-15
Hello,

I have a Ubuntu 12.04 machine. At times I see that there are some processes that are consuming very high CPU capacity. I was wondering if there is a script I can use that runs in the background on my machine that will log all the processes that consume more than 50% of the CPU capacity at any given time and log the output to a text file to review? Thank you.

A
0
Comment
Question by:aej1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 39240878
One way could put some command like the following in your cron.

ps ahkpcpu -o"%C%c" | while read c a;do if [[ `echo "$c >= 50" | bc` == 1 ]] ; then echo "$c $a"; fi; done >> /path/file

Open in new window



Although you man want to explore tools like sar that do historical record keeping.
0
 

Author Comment

by:aej1973
ID: 39241384
farzanj, thank you. The thing with sar is that, unlike top, it shows the CPU utilization but does not show which process has taken up the CPU capacity, am I right or am I missing something? Thank you.
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39241678
Not sure if you want the process id (PID) or the actual command, but to do both, just add in %p (process id) and %a (command) to the ps output options:
ps ahkpcpu -o"%p%C%c%a"

Open in new window

0
 
LVL 31

Accepted Solution

by:
farzanj earned 300 total points
ID: 39241694
Yes, you are right.  I was thinking about processors and processes.  So the this command or a modification of it should be your friend.

ps -eo"%C%c" | while read c a;do if [[ `echo "$c >= 50" | bc` == 1 ]] ; then echo "$c $a"; fi; done > /path/file 2> /dev/null

Open in new window

0
 

Author Closing Comment

by:aej1973
ID: 39250513
Thank you.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Issue with cURL on Windows 7 129
How to search a specific mailbox rule name in all mailboxes in Exchange 2010? 11 71
Shell Script- gzip 5 85
WMIC Output Formatting 1 84
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question