Solved

log processes with high CPU usage?

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Utilizing an array to gracefully append to a list of EmailAddresses
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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