在Linux中,您可以尝试以下操作:
top -bn1 > output.txt
来自man top
:
-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.
对于OS X,请尝试:
top -l 1
从OSX顶级手册页:
-l <samples>
Use logging mode and display <samples> samples, even if
standard output is a terminal. 0 is treated as infinity.
Rather than redisplaying, output is periodically printed in
raw form. Note that the first sample displayed will have an
invalid %CPU displayed for each process, as it is calculated
using the delta between samples.
top
在OS X上支持-b标志,这似乎正是我要寻找的答案。:-(可悲的是,这不,我没有看到一个版本,top
可以通过自制这似乎正是针对Linux的正确答案,寿。