Aug 09, '06 07:30:00AM • Contributed by: hysterion
- Taking k = 1, the CPU usage line and column stop making sense.
- With k > 1, they become skewed by an overestimated CPU usage for top itself.
- Either way, relaunching top every few seconds soon causes pid's to roll over 30000, so that recent processes must be hunted down the list rather than conveniently appearing on top.
Here's how to do it:
- In the GeekTool Preference Pane, make a new entry top.log of type File, with Path set to /var/tmp/top.log. This will make GeekTool always display the last 50 lines of this file -- internally it runs tail -n50 -F on it.
- Make another new entry of type Shell, with Command: top.py, Size: 0 by 0, Refresh: 10. Actually, our script will run only once, but for some reason GeekTool gets far more CPU-intensive if the Refresh field is empty or zero.
- Put the following script, top.py, in ~/Library/Application Support/GeekTool Scripts. Be sure to make it executable by running chmod a+x on it, so it will execute.
Here the os.system line spawns one top process, which forever (-l0) keeps sending 45 lines, every three seconds, to our top.log. The while loop then tames the log's growth by emptying it once a minute. Fewer than 45 lines works fine, but more seem to cause a jerky display.#!/usr/bin/env python import os, time os.system("top -l0 -n45 -s3 -S >> /var/tmp/top.log &") while True: open("/var/tmp/top.log","w").close() time.sleep(60) - Now click Enable GeekTool, select the top.log entry, and customize the window to taste, moving it up so that the first (50 - 45 = 5) lines hide above the Mac menu bar. Close the Pref Pane, and compare the result with top -s3 running in Terminal.
