How can I get running process list using Python on Linux?
I usually use ps -fA | grep python to see what processes are running. The CMD will show you what python scripts you have running, although it won't give you the directory of the script.
We would be using the WMI. Win32_Process function in order to get the list of running processes on the system. Then we called the function WMI. Win32_Process() to get the running processes, iterated through each process and stored in variable process.
IMO looking at the /proc
filesystem is less nasty than hacking the text output of ps
.
import os pids = [pid for pid in os.listdir('/proc') if pid.isdigit()] for pid in pids: try: print open(os.path.join('/proc', pid, 'cmdline'), 'rb').read().split('\0') except IOError: # proc has already terminated continue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With