Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'View valid 'top' output on the desktop via GeekTool' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
View valid 'top' output on the desktop via GeekTool
Authored by: jaysoffian on Aug 09, '06 06:11:23PM

You're not actually shrinking the log file. Even though you're truncating it with the python script, the top process's stdout file-descriptor maintains its position in the log. Hence when top produces new output the beginning of the log is filled with null bytes. Try this test. Open two terminal windows. In the first terminal window, simulate your top process with:

sh -c 'while :; do echo hello; sleep 1; done' >> /tmp/foo

Wait about 10 seconds.

Now in your second terminal window:

sh -c '>/tmp/foo'

Wait at least second and then kill the original "hello" process.

Now do an "od -a /tmp/foo" and notice the file is filled with nul bytes.

j.





[ Reply to This | # ]
View valid 'top' output on the desktop via GeekTool
Authored by: hysterion on Aug 09, '06 08:14:20PM
> "You're not actually shrinking the log file."

Well, I may be wrong, but believe it or not I did check this :-) I suggest you check your theory on the given script and not on a different one. Here then is what you get if you watch the log's growth:


$ while true; do ls -l /var/tmp/top.log; sleep 15; done
-rw-r--r--   1 fz  wheel  20090 Aug  9 22:52 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  40180 Aug  9 22:53 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  56252 Aug  9 22:53 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  0 Aug  9 22:53 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  20090 Aug  9 22:53 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  40181 Aug  9 22:54 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  56253 Aug  9 22:54 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  0 Aug  9 22:54 /var/tmp/top.log
-rw-r--r--   1 fz  wheel  20090 Aug  9 22:54 /var/tmp/top.log
^C
i.e. the size does shrink to zero once a minute. (You can also see this by opening the log in Console.app with a double click.) What you are describing is what would happen if I had used ">" in place of ">>" in the script's os.system line.

[ Reply to This | # ]
View valid 'top' output on the desktop via GeekTool
Authored by: hysterion on Aug 09, '06 09:03:09PM
> "Now do an "od -a /tmp/foo" and notice the file is filled with nul bytes."

Not on my machine:


$ sh -c 'while :; do echo hello; sleep 1; done' >> /tmp/foo
^C
$ od -a /tmp/foo
0000000    h   e   l   l   o  nl   h   e   l   l   o  nl                
0000014
(I've done as you say in the other Terminal.)
On the other hand, as I mentioned above, with ">" in place of ">>" you would get

$ sh -c 'while :; do echo hello; sleep 1; done' > /tmp/foo
^C
mini:~ fz$ od -a /tmp/foo
0000000  nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul nul
*
0000100  nul nul   h   e   l   l   o  nl   h   e   l   l   o  nl        
0000116
I hope this clears it up! (I'd rather keep the 5-line script than switch to one that makes 25...)

[ Reply to This | # ]