问题描述
我正在编写一个小python脚本来测试一些东西。后来我想用它与gnuplot一起创建资源使用情况图,但是首先进行一些测试。
I am writing a little python script to test some stuff. later I want to use it to create resource usage plots with gnuplot, but first a few tests.
脚本看起来像
import subprocess
result = subprocess.check_output("top -b -n 1 -c", shell=True).split("\n")
head = result[:5]
body = [x for x in result[7:] if x] #removes empty strings
for line in head:
print line
csum = 0.0
for line in body:
print line
csum += float(line.split()[8])
print "CPU usage of all processes added up", csum, "%"
多次运行它几乎总是导致显示的CPU使用率> 100%。有时甚至> 200%。
Running it multiple times almost always resulted in a shown CPU usage > 100%. Sometimes even > 200%. How can this be?
它运行在具有两个内核的虚拟机(virtualbox,ubuntu 14.04 64位)中。主机还具有两个内核。
It runs in a virtual machine (virtualbox, ubuntu 14.04 64 bit) with two cores. The host also has two cores.
所有正在运行的进程的使用值之和不总是低于100%吗?我在同一时间运行htop,这显示出每个内核上约有50%的负载...。
Shouldn't the sum of the usage values of all running processes be always lower than 100%? I am running htop at the same time and this shows me about 50% load on every core....
问题可能出在某些进程启动了其他进程而同时在顶部的输出中显示,而父进程也显示子级的CPU使用率? ==>孩子被计数两次?
Could the problem be that maybe some processes started others and both are shown in the output of top while the parent process also shows the cpu usage of the child? ==> child gets counted twice?
推荐答案
100%cpu的利用率是1 CPU / CORE / Thread。如果您有8个CPU,那么最大值将为800%。
a 100% cpu is a full utilization of 1 CPU/CORE/Thread. If you have, 8 CPU, then the maximum will be 800%.
如果您有线程,则故事会更复杂,因为线程不是真正的线程。 CPU,但是在Linux上,它被视为CPU。
If you have thread, the story is a bit more complicated, since a thread is not a real CPU, but, on Linux it is counted as a CPU.
这篇关于总的CPU使用率(最高输出)如何超过100%?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!