Solved

log processes with high CPU usage?

Posted on 2013-06-11
5
268 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
  • 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This Windows batch file is useful for organizing image files from a digital camera or other source, but can have many other uses.  It simply renames the file(s) to match their create date.  For example, if you took a picture today at 1:40pm and the …
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now