Linux上根据进程名kill掉指定的进程

Linux上根据进程名kill掉指定的进程

def kill_by_name(name):
    p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
    out, err = p.communicate()
    for line in out.splitlines():
        if name in line:
            pid = int(line.split(None, 1)[0])
            os.kill(pid, signal.SIGKILL)



你可能感兴趣的:(Linux上根据进程名kill掉指定的进程)