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.
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
Note the two
-woptions 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.