Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - get process names,CPU,Mem Usage and Peak Mem Usage in windows

Tags:

I am wanting to get a list of all the process names, CPU, Mem Usage and Peak Mem Usage. I was hoping I could use ctypes. but I am happy to hear any other options. Thanks for your time.

like image 479
Daniel Avatar asked May 01 '13 21:05

Daniel


People also ask

How do I get CPU utilization of a process in Python?

Get current CPU usage using psutil The function psutil. cpu_percent() provides the current system-wide CPU utilization in the form of a percentage.

How do I check memory utilization in Python?

You can use it by putting the @profile decorator around any function or method and running python -m memory_profiler myscript. You'll see line-by-line memory usage once your script exits.


1 Answers

You can use psutil.

For example, to obtain the list of process names:

process_names = [proc.name() for proc in psutil.process_iter()] 

For info about the CPU use psutil.cpu_percent or psutil.cpu_times. For info about memory usage use psutil.virtual_memory.

Note that psutil works with Linux, OS X, Windows, Solaris and FreeBSD and with python 2.4 through 3.3.

like image 178
Bakuriu Avatar answered Sep 21 '22 01:09

Bakuriu