# -*- coding: utf-8 -*-
import os
import subprocess
import time
def get_process_id(name):
child = subprocess.Popen(["pgrep", "-f", name], stdout=subprocess.PIPE, shell=False)
response = child.communicate()[0]
return [int(pid) for pid in response.split()]
if __name__ == '__main__':
name = "test06"
pids = get_process_id(name)
for pid in pids:
result = os.system("kill -9 {}".format(pid))
if result == 0:
print("kill -9 {} is success".format(name))
else:
print("kill -9 {} is failed".format(name))
【python】根据进程名,删除进程
于 2022-06-04 20:25:45 首次发布