2021년 3월 19일 금요일

[python] cmd kill in code

 


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

댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...