
$ – requires given linux commands to be executed as a regular non-privileged userĪ great way to check the current CPU usage is with the top command. # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command Privileged access to your Linux system as root or via the sudo command. Requirements, Conventions or Software Version Used Warning: the first time this function is called with interval = 0.0 or None it will return a meaningless 0.0 value which you are supposed to ignore.How to Check and Monitor CPU utilization on Linux Software Requirements and Conventions Used Software Requirements and Linux Command Line Conventions Category The order of the list is consistent across calls. First element of the list refers to first CPU, second element to second CPU and so on.

When percpu is True returns a list of floats representing the utilization as a percentage for each CPU.

In this case it is recommended for accuracy that this function be called with at least 0.1 seconds between calls. That means the first time this is called it will return a meaningless 0.0 value which you are supposed to ignore. When interval is 0.0 or None compares system CPU times elapsed since last call or module import, returning immediately. When interval is > 0.0 compares system CPU times elapsed before and after the interval (blocking). Return a float representing the current system-wide CPU utilization as a percentage.


Psutil.cpu_percent(interval=None, percpu=False) Individual CPUs: 11.00% 8.50% 11.90% 8.50% 9.90% 7.60% 11.50% 12.30%įor more information on how the psutil.cpu_percent(interval=2) python call works, see the official psutil.cpu_percent(interval=None, percpu=False) documentation here: Sample output: notice that I have 8 cores, so there are 8 numbers after "Individual CPUs:": Total: 10.15% printf "%b" "import psutil\nprint(''.format(' '.join(cpu_percent_cores_str)))\n\ This calls python3 and uses the cross-platform psutil module.
