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.
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.
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.
To sort all running processes by CPU utilization, simply press Shift+P key.
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.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With