title: How to get Process ID with name in python
body: <p>I am trying to build a simple python script that does one thing right now: it finds the process id of a process given it's PID. I have looked on here and found many different resources, but none that quite fit what I need. The most helpful is <a href="https://stackoverflow.com/questions/26688936/how-to-get-pid-by-process-name-in-python">this one</a> and I have used their example to try to make progress.</p>
  
  <p>Right now I have this:</p>
  
  <pre><code>from subprocess import check_output
  
  def get_pid(name):
      return check_output(["pidof",name])
  
  print(get_pid("fud"))
  </code></pre>
  
  <p>I am using sudo top to view all my processes in a different terminal window. There is one process in particular named "fud" that I see on the screen and know that it is running. When I run the program for that process and any other process I get this: </p>
  
  <pre><code>  File "fort.py", line 6, in &lt;module&gt;
      print(get_pid("fud"))
    File "fort.py", line 4, in get_pid
      return check_output(["pidof",name])
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
      process = Popen(stdout=PIPE, *popenargs, **kwargs)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
      errread, errwrite)
    File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
      raise child_exception
  OSError: [Errno 2] No such file or directory
  </code></pre>
  
  <p>I am not really sure what is going on here, and would like detailed guidance on an effective way to correct this mistake and do what I am trying to do. Thanks!</p>