윈도우 프로세스 실행시간 가져오기 (wmic process get)

윈도우 프로세스 실행시간 가져오기 (wmic process get)

일반적으로 윈도우에서 프로세스 목록을 가져오기 위해서는 cmd 에서 tasklist 라는 명령어를 사용한다.

1. tasklist

그러나 이것으로 프로세스 아이디(PID)는 얻을 수 있어도, 프로세스를 실행한 시간은 알 수 없다.

프로세스를 실행한 시간을 알기 위해서는 wmic process get 명령어를 사용한다.

2. wmic process get processid,caption,creationdate,ThreadCount | findstr exe

위 명령어를 통해 프로세스 아이디(processid)와 실행을 시작한 시간(creationdate), 쓰레드 카운트(ThreadCount) 등을 알 수 있다.

참고로 윈도우에서 process 를 kill 하기 위해서는…

taskkill /f /im 종료할_프로그램 .exe

또는

taskkill /f /im 종료할_프로그램_프로세스_아이디

를 사용하면 된다.

/f 를 안넣으면 그 프로그램에 종료 신호를 보내고 넣으면 강제 종료한다.

3. wmic 사용 시 findstr 을 사용하지 않는 방법

where name=”이름”을 사용하면 된다.

ex) wmic process where name=”notepad.exe” get processid,caption,creationdate,ThreadCount

4. wmic 사용 시 원하는 포맷으로 변경하는 방법

예를 들어 구분자를 탭이 아닌 쉼표로 바꾸고 싶은 경우, 명령어 뒤쪽에 /format:csv 를 붙이면 된다.

ex) wmic process where name=”notepad.exe” get processid,caption,creationdate,ThreadCount /format:csv

xml 형식은 명령어 뒤쪽에 /format:xml 을 붙이면 된다.

ex) wmic process where name=”notepad.exe” get processid,caption,creationdate,ThreadCount /format:xml

그 외에도 다음과 같은 포맷들이 있다. (출처 : https://www.vanstechelman.eu/windows/wmic/output_formats)

CSV
HFORM
HMOF
HTABLE
HXML
LIST
RAWXML
TABLE
VALUE
htable-sortby
htable-sortby.xsl
texttablewsys
texttablewsys.xsl
wmiclimofformat
wmiclimofformat.xsl
wmiclitableformat
wmiclitableformat.xsl
wmiclitableformatnosys
wmiclitableformatnosys.xsl
wmiclivalueformat
wmiclivalueformat.xsl