def check_pid(pid):
    """ Check For the existence of a unix pid. """
try:
    os.kill(pid, 0)
except OSError:
    return False
else:
    pass
How to check if there exists a process with a given pid in Python?