I'm trying to get the pid with the help of process name. i have tried this solution. But it gives me this error
Traceback (most recent call last):
File "pidName.py", line 10, in <module>
getPIDs("safari")
File "pidName.py", line 4, in getPIDs
pidlist = map(int, s.check_output(["pidof", process]).split())
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 567, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
and the code is this :
import subprocess as s
def getPIDs(process):
try:
pidlist = map(int, s.check_output(["pidof", process]).split())
except s.CalledProcessError:
pidlist = []
print 'list of PIDs = ' + ', '.join(str(e) for e in pidlist)
if __name__ == '__main__':
getPIDs("safari")
Since, i'm new to these things. I'm unable to solve this problem. But in the solution it works. But somehow it doesn't on my Mac. I'm using mac. and running the python script from terminal.
which python
gives me this result:-
/usr/local/bin/python
so, i'm using the inbuilt python version i think.
can anyone help me with this problem.