I am writing a little python script to test some things. later I want to use it to create graphs of resource usage using gnuplot, but first a few tests.
the script looks like
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]
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, "%"
Running it several times almost always led to the CPU utilization shown> 100%. Sometimes even> 200%. How can it be?
It runs on a virtual machine (virtualbox, ubuntu 14.04 64 bit) with two cores. The host also has two cores.
Should the sum of the usage values ββof all running processes always be below 100%? I run htop at the same time, and this shows me about 50% of the load on each core.
, , , , top, cpu ? == > ?