![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| find and replace command in one line using one command | vasikaran | UNIX for Dummies Questions & Answers | 10 | 08-20-2008 07:40 AM |
| A utility for sending complex email messages from the command line | iBot | UNIX and Linux RSS News | 0 | 06-06-2008 01:50 AM |
| how to? launch command with string of command line options | TinCanFury | Shell Programming and Scripting | 5 | 04-28-2008 03:06 PM |
| command line socket read utility | axes | High Level Programming | 3 | 11-20-2007 02:45 PM |
| Compound command with 'find' utility? | deckard | Shell Programming and Scripting | 6 | 10-05-2005 01:27 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
top command line utility
I'm writing a monitoring application. I'd like to periodically get the information provided by the 'top' command line utility from within my code and write the output of 'top' to a file. Wondering if anyone has already done something like this.
Doing system("top > someFile"); does not create the file since it depends on the terminal. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
What information are you trying to get? What platform and Unix are you using? Running a curses-based app that imposes a measurable amount of load on it's own doesn't sound optimal to me - perhaps there's a way to avoid using 'top -b' to get what you want.
|
|
#3
|
|||
|
|||
|
We have a robotics app that is dying. It's usually because a thread is in a tight loop. So I'd like to get cpu usage info. I've been looking at the top code and trying to extract the actual reading of the system info. It's mainly screen handling code. I'm actually building a framework for monitoring real time systems. This app is a small plug in component to that framework.
thanks |
|
#4
|
||||
|
||||
|
This worked for me to get a top snapshot (I'm running bash in Ubuntu 7.10):
top -b -n 1 > ~/Desktop/top.txt I did a man top to find out that: -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. -n : Number of iterations limit as: -n number Specifies the maximum number of iterations, or frames, top should produce before ending. |
|
#5
|
||||
|
||||
|
I have OpenSuse 10.2 installed and I tried top command like this:
top -b -n 5 -d 3.0 -H > ~/Desktop/top_info.txt -b - Batch mode -n - how many itterations -d - delay of each of each output -H - out the threads It works on my PC perfectly. |
|
#6
|
|||
|
|||
|
Curious - my post disappeared!
|
|
#7
|
||||
|
||||
|
Well, if you insist on using top, double-check the man page. I found this in mine (shipped with GNU procps-3.2.7-8.1.el5):
Quote:
BTW, I'm not sure if you mean RTOS, but if you really need this to be real-time, I'd definitely minimize the impact of monitoring as much as possible. |
||||
| Google The UNIX and Linux Forums |