Questions tagged [psutil]

psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python.

psutil (process and system utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network) in Python. It is useful mainly for system monitoring, profiling and limiting process resources and management of running processes. It implements many functionalities offered by command line tools such as: ps, top, lsof, netstat, ifconfig, who, df, kill, free, nice, ionice, iostat, iotop, uptime, pidof, tty, taskset, pmap. It currently supports Linux, Windows, OSX, Sun Solaris, FreeBSD, OpenBSD and NetBSD, both 32-bit and 64-bit architectures, with Python versions from 2.6 to 3.5.

Resources:

481 questions
5
votes
2 answers

How to get disk IO and network usage as percent by psutil

Is there a way to get disk IO and network usage as a percentage by psutil. I found some useful function. But I don't know, how to get as a percentage using psutil.disk_io_counters() psutil.net_io_counters()
irmorteza
  • 1,576
  • 3
  • 19
  • 32
5
votes
2 answers

psutil.process_iter() doesn't return all running processes

I'm using psutil 2.1.2 on python 64 bit on windows 8.1. I'm using psutil.process_iter() to iterate over the running processes to get details on a specific process. for some reason I don't get the process even though it is displayed in the Task…
Ido A
  • 87
  • 1
  • 1
  • 8
5
votes
1 answer

Ways to free memory back to OS from Python?

I have code that looks similar to this: def memoryIntensiveFunction(x): largeTempVariable = Intermediate(x) processFunction(largeTempVariable,x) The problem is that the variable temp is something like 500 mb in a test case of mine, but that…
amos
  • 5,092
  • 4
  • 34
  • 43
4
votes
1 answer

use 'pip install psutil' on docker image python:3.9.13-alpine3.16 error: linux/ethtool.h not found

I tried to install python module psutil in docker python:3.9.13-alpine3.16 But it reported the following mistake: Building wheels for collected packages: psutil Building wheel for psutil (pyproject.toml) ... error error:…
Guf
  • 149
  • 1
  • 7
4
votes
1 answer

How do I get cpu_times of process run with psutil.Popen after it is finished but before it is terminated

I would like to use the cpu_times() method of a psutil.Popen object to find the cumulative values after it has finished. I first tried the following: p = psutil.Popen("stress --cpu 3 -v -t 15", shell=True) p.wait() cpuTimes = p.cpu_times() However,…
tintedFrantic
  • 177
  • 1
  • 9
4
votes
1 answer

Efficiently retrieving stats for all running processes using `psutils`

I am buidling a utility which retrieves information for all the running processes on the OS (Centos 7) using Python 3.6.5. I created the following function for that matter, using psutil: def get_processes(self): fqdn = self.get_FQDN() …
Matan Bakshi
  • 183
  • 1
  • 9
4
votes
3 answers

Glances psutil warning scrolling the console

Glances v2.11.1 with psutil v5.4.3 /usr/lib/python3.6/site-packages/psutil/_pslinux.py:1152: RuntimeWarning: ignoring OSError(6, 'No such device or address') warnings.warn("ignoring %r" % err, RuntimeWarning) OS is antegos running…
Jan Göbel
  • 41
  • 4
4
votes
1 answer

pid of executing python script using psutil

OS: Jessie Python: 2.7 I want to use psutil to terminate my script I am currently executing. My problem is that I would like to kill it with the ID but I don't know how to get the pid of my script. I know I can terminate with the names of…
Tim
  • 105
  • 1
  • 6
4
votes
1 answer

install latest psutil version in centos 6.7

My system os version is (centos)6.7 with installed python version is 2.6.* When I tried to install a python module psutil with a command yum install python-psutil But the installed version is 0.3.6 something... But the latest version of psutil…
chikku
  • 863
  • 1
  • 7
  • 19
4
votes
1 answer

Python psutil not showing all child processes

I have a small python script, that essentially looks like the following: import os import psutil def processtree(): pid = os.getpid() # have to go two levels up to skip calling shell and # get to actual parent process parent =…
Sagar
  • 9,456
  • 6
  • 54
  • 96
4
votes
3 answers

psutil - getting process name is blank

I'm trying to run this code and I'm not getting the list of processes by name: import psutil PROCNAME = "python.exe" for proc in psutil.process_iter(): if proc.name == PROCNAME: print proc What I get is nothing even though the process…
lia1000
  • 159
  • 1
  • 4
  • 13
3
votes
1 answer

Why I do get an error when installing the psutil package for python?

I installed pyhton on a windows 64bit machine (Version 3.10). Afterwards I like to install psutil with: python -m pip install psutil but I get following error message: Collecting psutil Using cached psutil-5.8.0.tar.gz (470 kB) Preparing…
KD17
  • 35
  • 1
  • 1
  • 8
3
votes
2 answers

Why am I getting access denied when program is not running?

I have a simple piece of code taken mostly from this answer, with some adjustments: import psutil try: if "firefox.exe" in (p.name() for p in psutil.process_iter()): print('Firefox is running') else: print('Firefox is not…
Have a nice day
  • 1,007
  • 5
  • 11
3
votes
1 answer

Python - Getting Total RAM Size

I need to get total RAM size in gigabytes (e.g. 8 GB or 8.0 GB). It gives as bytes and I convert it into GB by dividing 1024x1024x1024. As a result it gives a number smaller than 8 (e.g. 7.7). How can I get the size as 8 GB? NOTE: I have used…
demirod
  • 81
  • 15
3
votes
2 answers

CPU utilization during testing in Python?

I want to get the cpu usage during testing for my ML model (during a call to predict). Here is currently what I am doing. p is the current process: start = p.cpu_percent(interval=1) y_hat = clf.predict(X_test) print(abs(p.cpu_percent(interval=None)…
Yurroffian
  • 61
  • 2
  • 6
1 2
3
32 33