I'd like to know if it's possible to find out the "command" that a PID is set to. When I say command, I mean what you see in the last column when you run the command "top" in a linux shell. I'd like to get this information from Python somehow when I have a specific PID.
Any help would be great. Thanks.
The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
ps command is used to list the currently running processes and their PIDs along with some other information depends on different options.
Using a /proc files has a disadvantage of lower portability, which may or may not be a concern. Here's how you can use the standard shell command for that
ps -w -w -p <YOUR PID> -o cmd h
Note the two -w
options that instructs ps to not truncate the output (which it does by default)
Reading its output from python is as simple as calling a single function subprocess.check_output()
documented here.
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