How do you get the process ID of a program in Unix or Linux using Python?


I'm writing some monitoring scripts in Python and I'm trying to find the cleanest way to get the process ID of any random running program given the name of that program

something like

ps -ef | grep MyProgram

I could parse the output of that however I thought there might be a better way in python

10/12/2016 7:17:52 PM

Accepted Answer

Try pgrep. Its output format is much simpler and therefore easier to parse.

9/21/2010 4:00:23 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow