def is_process_running(pid): from yabi.backend.utils import execute args = ["ps", "-o", "pid=", "-p", pid] process = execute(args) stdout, stderr = process.communicate(None) return (pid in stdout)
def kill_process(pid, with_SIGKILL=False): logger.info("Killing process (SIGKILL=%s) %s", with_SIGKILL, pid) from yabi.backend.utils import execute args = ["kill"] if with_SIGKILL: args.append("-KILL") args.append(pid) process = execute(args) stdout, stderr = process.communicate(None) status = process.returncode if status != 0: logger.error("Couldn't kill process %s. STDERR:\n%s", pid, stderr)