10

I know that after running top, I can press 1 and get a list of the CPUs with their utilization percentages. I suspect I can do this in batch mode too with the -b option, but I don't know how, and I cannot find it in the manual.

I need to read it periodically from a python program, so it must be in batch mode.

1

3 Answers 3

10

You can use a configuration file for this. The easiest way is to open top, and configure it the way you want. In this case, that means using 1 to get the per-CPU listing. Then have it write a configuration file with Shift+W. After that, it will use that config file whenever that user runs top, and keep the same appearance, even in batch mode.

Note that you'll probably need a $HOME variable defined, if you're using this via cron, or some other environment lacking the standard login definitions.

1

I am not familiar with a way to do that with top, but you might have a look at mpstat which will show cpu utilization per core.

1
  • 1
    My system doesn't appear to have that, and I cannot install anything :(
    – Nathan
    Commented Jun 22, 2010 at 17:41
1
# mpstat -P ALL 1

10:54:41 PM  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest   %idle
10:54:42 PM  all    8.20    0.12    0.75    0.00    0.00    0.00    0.00    0.00   90.93
10:54:42 PM    0   24.00    0.00    2.00    0.00    0.00    0.00    0.00    0.00   74.00
10:54:42 PM    1   22.00    0.00    2.00    0.00    0.00    0.00    0.00    0.00   76.00
10:54:42 PM    2    2.02    1.01    0.00    0.00    0.00    0.00    0.00    0.00   96.97
10:54:42 PM    3    2.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   98.00
10:54:42 PM    4   14.15    0.00    1.89    0.00    0.00    0.00    0.00    0.00   83.96
10:54:42 PM    5    1.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
10:54:42 PM    6    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
10:54:42 PM    7    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .