본문 바로가기

개발이야기

Windows에서 Process ID 추출하여 kill 하는 방법

가끔씩 windows 서버를 다룰 때가 있다.

이럴 경우 WAS 와 같은 경우 문제가 생기면 자동으로 kill 하고 Alarm 처리 후 다시 restart 하는 일련의 script 들이

Linux의 경우는 샘플로 제법있는데, windows 서버는 참으로 찾기 힘들다.

그런데, windows 창 이름을 가지고 process id를 찾아서 kill 하는 방법이 stackoverflow에 있길래 우선 정리해본다.

(고마운 stackoverflow ^^)

아직 테스트는 안해봤지만, 제법 유용할듯하다.

참고 URL : https://stackoverflow.com/questions/9486960/how-to-get-pid-of-process-just-started-from-within-a-batch-file/51319981

====================================================================

Start multiple processes in parallel:

start "<window title>" <command will be executed>

Example:

start "service1" mvn clean spring-boot:run

start "service2" mvn clean spring-boot:run

Obtain the PID of the processes (optional):

tasklist /V /FI "WindowTitle eq service1*"

tasklist /V /FI "WindowTitle eq service2*"

Kill the processes:

taskkill /FI "WindowTitle eq service1*" /T /F

taskkill /FI "WindowTitle eq service2*" /T /F

====================================================================