Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU usage in top batch mode

I have a problem that makes me mad. I am running top in batch mode with the following command,

top -b -n 1

The problem is I can run top in batch mode 100 times but the CPU usage never changes past the original value. The memory usage changes as expected but CPU stays the same. If I simultaneously run another top in a different window the CPU usage is changing for that top but not for the top in batch mode.

Basically CPU stats don't seem to change in batch mode and do in interactive mode. Does anyone know why? Try it yourself, run the above command a few times and observe the CPU usage staying the same then run top in interactive mode and observe the CPU usage constantly changing.

like image 417
toc777 Avatar asked Dec 01 '10 14:12

toc777


People also ask

What is batch mode in top?

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 does not accept input and runs until the iterations limit you've set with the '-n' command-line option, or until killed.

What is CPU usage in top command?

The top command calculates the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. For example, suppose we set two seconds as the refresh interval, and the CPU usage reports 50% after a refresh.

How do you sort CPU usage on top?

To sort all running processes by CPU utilization, simply press Shift+P key.

How do I find the top 10 memory consuming process in Linux?

Use ps Command to Find Top Processes by Memory and CPU Usage ps is a Linux command-line utility with many options that helps you to display output in different formats. You can use the ps command with –sort argument to sort the output by memory and CPU usage.


1 Answers

On the first iteration, it is showing you the average CPU usage since system startup.

(Note that this is no longer the case for newer versions of top).

like image 98
caf Avatar answered Sep 22 '22 20:09

caf