def process_Kill(exeName):
# python filename.py로 실행된 프로세스를 찾음
for proc in psutil.process_iter():
try:
# 프로세스 이름, PID값 가져오기
processName = proc.name()
processID = proc.pid
# print(processName)
if processName[:3] == "cmd":
# print(processName)
commandLine = proc.cmdline() # 동일한 프로세스 확인. code 확인
print(commandLine)
for item in commandLine:
if exeName in item:
parent_pid = processID # PID
print("PID %s" % parent_pid)
parent = psutil.Process(parent_pid) # PID 찾기
for child in parent.children(recursive=True): # 자식-부모 종료
child.kill()
parent.kill()
# print(processName, ' ', commandLine, ' - ', processID)
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
pass
댓글 없음:
댓글 쓰기