

The while loop then tames the log's growth by emptying it once a minute. #!/usr/bin/env pythonimport os, timeos.system("top -l0 -n45 -s3 -S > /var/tmp/top.log &")while True: open("/var/tmp/top.log","w").close() time.sleep(60)Here the os.system line spawns one top process, which forever ( -l0) keeps sending 45 lines, every three seconds, to our top.log. Be sure to make it executable by running chmod a+x on it, so it will execute.

With k > 1, they become skewed by an overestimated CPU usage for top itself.Taking k = 1, the CPU usage line and column stop making sense.Unfortunately it doesn't support self-updating commands like top, and the official workaround (break the loop with top -l k and set Refresh to keep restarting it) is rather Heisenbuggy:
TOP CPU PROCESSES GEEKTOOL FREE
The great and free GeekTool ( PowerPC | Intel) can write the contents of any file, and the output of any shell command, right onto the desktop.
