How to get PID by process name?
You can get the pid of processes by name using pidof through subprocess.check_output: from subprocess import check_output def get_pid(name): return check_output([“pidof”,name]) In [5]: get_pid(“java”) Out[5]: ‘23366\n’ check_output([“pidof”,name]) will run the command as “pidof process_name”, If the return code was non-zero it raises a CalledProcessError. To handle multiple entries and cast to ints: from subprocess import … Read more