[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

log processes with high CPU usage?

Posted on 2013-06-11
5
Medium Priority
?
299 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 1200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

656 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