Less intrusive way to capture CPU usage on Linux

2019-07-30 00:39发布

How does a tool like Net-SNMP captures CPU usage?

And what would be the least intrusive way to do it under Linux?

Less intrusive in the way that doing so would consume the least amount of machine resources (both cpu and ram) in order to do it. Eventually the data will be saved into a file.

3条回答
够拽才男人
2楼-- · 2019-07-30 00:41

try this:

ps -eo pcpu,pid | less

This will show the CPU usage along with the PIDs

查看更多
小情绪 Triste *
3楼-- · 2019-07-30 00:50

There is no other way to calculate the current CPU utilization than reading /proc except for the kernel itself. All common tools like ps, top etc. are also just reading /proc, either /proc/stat for an overall CPU usage or /proc/<pid>/stat for a per-process CPU usage. However as /proc is a virtual file system directly provided by the kernel the overhead for reading files in it is way smaller than for regular files.

If you don't want to read /proc yourself try to use a tool that does only little extra computations, like ps as mentioned by @deep.

查看更多
Anthone
4楼-- · 2019-07-30 01:05

Have you tried using the $top command?

in fact, here is a list of methods including the $top one, try these :)

http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html

查看更多
登录 后发表回答