First of all if this has been asked before I'm sorry for the duplicate, but I couldn't find the answer to my question anywhere.
So, I am pretty new to Python, and I am currently working on a wrapper for a web application. This wrapper starts a subprocess using Popen and then sends information about that subprocess to the web application. Everything is working great so far.
Now the only question I have is; Is it possible to get resource usage of a subprocess (RAM and CPU)?
If so, how would I go about doing that? Something cross-platform would be awesome, but a different method for Windows, Mac and Linux would work as well.
If it isn't possible to get via subprocess. How would I got about fetching resource usage from another process?
Any help would be appreciated!
Thanks for your time!
psutil
provides a cross-platform solution to get resource usage of a subprocess e.g.:to get the info for an existing
subprocess.Popen
instance just passpopen_instance.pid
topsutil.Process
. You could also create a subprocess usingpsutil.Popen
directly.