LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-01-2005, 04:47 AM   #16
Volcano
Member
 
Registered: Sep 2005
Posts: 225

Original Poster
Rep: Reputation: 15

yes, puffinman . that works.

but i have trouble there if i do that way.

i have writen a java code to read the file, but sometimes it is producing result and sometimes it is not producing result.

my java code follows the following logic

1) It locks the log file wth FileLock.
2)it reads the file.
3)prints the file.
4)unlocks the file.

but when i run this java code sometimes i get the file output sometimes i dont get the output.

so, at some point of time i may not get the output from my java code and for that reason my whole code would be erroneous .

the following observation i have noticed when i run your code.

i saw the log fle size is changing form 0 to 5.8 MB very rapidly (because of overwrite ?).

may be when my java code is reading the log file the file size is 0 and as a result java code is not outputting anything.

but somehow, i have to recover this problem. i need the CPU data correctly whenever i need it.
 
Old 10-01-2005, 06:18 AM   #17
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
So your original question wasn't really "I need to write the output of top to a file", it was rather "I need to get the output of top into my java program." In fact, writing it to a file is not the optimal solution (for reasons you are describing). Opening a child top process from Java and piping its output directly to your running program is more along the lines of what you want. I am sure it is possible in Java but I could not tell you how.

In general you should ask what you are really trying to do rather than only asking about what you think the answer is.

And by the way, a 5.8 MB top listing?? How many processes are running on your computer??
 
Old 10-01-2005, 06:37 AM   #18
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Quote:
Originally posted by puffinman
In general you should ask what you are really trying to do rather than only asking about what you think the answer is.
Excellent advice.
Read the data directly from /proc - at whatever frequency you decide upon; just like top probably does. This is a pseudo filesystem - for simplicity, you can assume the data only exists when you request it.
 
Old 10-15-2008, 10:02 PM   #19
lienh
LQ Newbie
 
Registered: Oct 2008
Posts: 3

Rep: Reputation: 0
Puffman, thank you for your answer. It's really useful.
Perl rocks.
 
  


Reply



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
command top getting error bluenectar Linux - General 2 08-19-2005 09:37 PM
Schedule TOP command in Crontab. imsajjadali Red Hat 2 05-20-2004 04:12 AM
top command, being hacked? shanenin Linux - Software 4 10-30-2003 08:25 PM
Results from top command...user Q...? cbjhawks Linux - Software 1 09-20-2003 10:06 PM
Where i can get the source code of the command 'top' hustning Programming 2 03-31-2002 12:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:57 PM.

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