eligro
eligro

Reputation: 845

Is there a way to get processes information of local machine with python?

I want something that will receive me the processes details, like I receive with 'ps' command in linux,

get 2 basically types- CPU usage and Memory Used.

today to get this I am using uncomfortable way:

subprocess.check_output(["ps", "aux"])

........

and parse the output of this..

any idea or solution way is acceptable!

Thanks!

Upvotes: 1

Views: 2135

Answers (2)

pyfunc
pyfunc

Reputation: 66719

I would suggest that you use psutil

Typical usage and example for a process:

psUtilInfo - psutil.Process(pid)
cpuPercentage = int(psUtilInfo.get_cpu_percent())
memoryInfo, _vms =psUtilInfo.get_memory_info()

To get all processes

psutil.get_pid_list()

I think you can also get more information like this from this module.

Upvotes: 4

Jeremiah
Jeremiah

Reputation: 1455

Checkout the psutil package. I don't know of a way using strictly the stdlib.

Upvotes: 5

Related Questions