Cross-platform way to get PIDs by process name in python
Asked 07 September, 2021
Viewed 796 times
  • 62
Votes

Several processes with the same name are running on host. What is the cross-platform way to get PIDs of those processes by name using python or jython?

  1. I want something like pidof but in python. (I don't have pidof anyway.)
  2. I can't parse /proc because it might be unavailable (on HP-UX).
  3. I do not want to run os.popen('ps') and parse the output because I think it is ugly (field sequence may be different in different OS).
  4. Target platforms are Solaris, HP-UX, and maybe others.

9 Answer