LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-30-2006, 01:02 PM   #1
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,458

Rep: Reputation: Disabled
Keeping track of process CPU %


Just wondered if anyone knows a way of logging top command for maybe an hour or so. I seem to get a process taking a high % of cpu, which I notice when playing fullscreen games that begin to stutter and slow down. This has only happened during the last few weeks and I suspect maybe fetchmail or a related process is the cause but would like to know for certain.
 
Old 03-30-2006, 03:04 PM   #2
celejar
Member
 
Registered: Oct 2003
Location: New York
Distribution: Debian Sid
Posts: 185

Rep: Reputation: 30
From the top(1) man page:

Quote:
-b : Batch mode operation
Starts top in 'Batch mode', which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you've set with the '-n' command-line option or until killed.
So just set the iteration number and delay time (with -n xxx -d yyy) and redirect the output to your logfile - voila!
 
Old 03-30-2006, 03:05 PM   #3
amon
Member
 
Registered: May 2004
Location: UK
Distribution: Debian, Ubantu, CentOS
Posts: 146

Rep: Reputation: 17
Rtfm

I hate to say something that I find annoying in my posts but...

If you look at the man page:
Code:
man top
it will say that you can use the -b switch for batch mode. this produces a nice output that you can pipe to annother application such as
Code:
top -b|grep cron
this allows you to watch an individual program

or you can output to a text file (using output redirect):
Code:
top -b>toplog.txt
or a combination of the two:
Code:
top -b|grep cron>toplog.txt
that answer the question?

p.s. if you didn't know about the man function or the pipe or redirecting of output then sorry about the RTFM
 
Old 03-30-2006, 03:09 PM   #4
sadarax
Member
 
Registered: Sep 2005
Distribution: Ubuntu
Posts: 250

Rep: Reputation: 30
Quote:
Originally Posted by amon

or a combination of the two:
Code:
top -b|grep cron>toplog.txt
You may also want to use the '>>' to append to the file, instead of overwrite it.
 
Old 03-30-2006, 03:42 PM   #5
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,458

Original Poster
Rep: Reputation: Disabled
Thx for the info, I did indeed try top -b | head and top -b > toplog but in the first case it stopped after 5 secs or so, and in the 2nd it didnt seem to be working as i expected. IE I could only get the processes at the moment I ctrl-c'd to end it.

Probably need to experiment with iterations.
 
Old 03-30-2006, 03:45 PM   #6
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
try running this
you can redirect it to a file or whatever and change intevals (seconds)
have to chmod 755 to make it runnable
oh yea the fourth collumn is recent CPU activity
Code:
#!/bin/bash
INTERVAL=10
LIMIT=3600 
while [ "$SECONDS" -le "$LIMIT" ]
do
    date
    ps -ef | egrep -v "STIME|$LOGNAME" | sort +3 -r | head -n 15
    sleep $INTERVAL
done
exit 0
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping track of logs mijohnst Linux - Software 1 03-29-2006 09:02 PM
Keeping track of my threads? une LQ Suggestions & Feedback 4 04-10-2005 11:35 PM
Volunteer needs help keeping track. mimsmall Linux - Software 1 10-10-2004 03:03 PM
keeping track of active desktops jalburger Linux - Newbie 0 07-02-2002 09:02 AM
Keeping track of packages NSKL Slackware 2 06-28-2002 11:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration