import subprocess, signal import os #kill process to make sure, that the handler is Terminate incase handler having problem receiving # terminate message from controller def killProc(): # define process name of the Handler procName1 = 'foo' #procName = 'SIP Handler' p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE) out, err = p.communicate() #search process name and kill it. for line in out.splitlines(): if procName1 in line: pid = int(line.split(None, 1)[0]) os.kill(pid, signal.SIGKILL) killProc()