Operating System - HP-UX
1846636 Members
1617 Online
110256 Solutions
New Discussion

Executing 'TOP' in the background

 
SOLVED
Go to solution
Anand_30
Regular Advisor

Executing 'TOP' in the background

Hi All,

I have one application running in my redhat LINUX box for 10-15 hours. I need to monitor the CPU usage of the system during the time the application is running. Can anyone tell me how I would execute "TOP" utility in the background for the amount of time my application is running and gather the information in specified files to be analyzed at the end of the day.

Thanks,
Andy
7 REPLIES 7
Sridhar Bhaskarla
Honored Contributor

Re: Executing 'TOP' in the background

Hi Andy,

There is an option "-f" that can be given with top to capture the data in a file on HP systems. For ex.,

top -s5 -d6 -f top.out

Will capture the data for 30 seconds for every 5 seconds.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
D Block 2
Respected Contributor

Re: Executing 'TOP' in the background

I think Sri, is on to it..

might I add my 2-cents here..

try also:

$ w

$ uptime

and of course, check out the man pages on uptime, sar, cron, etc.

Golf is a Good Walk Spoiled, Mark Twain.
Bharat Katkar
Honored Contributor

Re: Executing 'TOP' in the background

Andy,
Top will definitely do the trick.
Also you can use SAR (System Activity reporter to get the Statistics)
Use: # sar -u
See man sar to get more details.
Regards,
You need to know a lot to actually know how little you know
Muthukumar_5
Honored Contributor
Solution

Re: Executing 'TOP' in the background

If you want to monitor the specific application with top then,

make a script as,

# Start the application
..........

# get the process count
count=$(ps -ef | grep -v grep | wc -l)

# Run the top as,
top -d 1 -f filename -n $count

It will update the top information's of all process there in filename

Note: top will run only once.

If you want automate then,

try to put in loop as,


while true; do

# top execution
# Sleep time
# check process running / stopping
# If stopped,
stop execution

done

Use file on top as with time and date or counts to identify the information

Easy to suggest when don't know about the problem!
Franky_1
Respected Contributor

Re: Executing 'TOP' in the background

Hi,

you could run the "top" command with the "-f" option which writes into a file (in the background)

top -d -f

Regards

Franky

Don't worry be happy
Anand_30
Regular Advisor

Re: Executing 'TOP' in the background

Thanks all for the reply. I have one more query. I don't find the '-f' option for 'top' in redhat LINUX. It has '-b' option but this option does not seem to work for collecting the outputs in a particular file. When I redirect the output of 'top' to a file, I find that there are lots of special charaters in the file.

Can anyone please help me out of this

Thanks,
Andy
Muthukumar_5
Honored Contributor

Re: Executing 'TOP' in the background

We can do it very effeciently as,

# Collect process id of started process
top -p -n 1 -b

It will give the informations of that process at that time ( only one count )


If you want then redirect into one analysis file as,

top -p -n 1 -b > /tmp/topinfo_.log

Note: And it is HP-UX related one. If you want the specific then go on linux related on itrc. :-)

HTH.
Easy to suggest when don't know about the problem!