27

Is there any simple way to show how long a specific PID instance has been active?

3 Answers3

34

Using the Powershell Get-Process cmdlet:

Get-Process | Select-Object id, starttime, name | Sort-Object id

Davidw
  • 1,210
  • 3
  • 14
  • 24
11

Gregg,

I know that Process Explorer will show this, sort of.

Get it here: http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx

If you run it, right click on a process and choose Properties it will show you the start time of the process (and you can click on the Threads tab there to see individual thread start times).

enter image description here

Alternatively in Process Explorer you can click View, Select Columns, choose the Process Performance tab, and choose Start Time and then it will show that column in the main window for all PIDs.

You might need to do your own math on the individual threads within that process (again the threads tab) and the current date/time to get a true "how long" answer.

TheCleaner
  • 32,352
  • 26
  • 126
  • 188
0

In CMD you can use standard Windows Management Instrumentation Command-line (WMIC) utility to get the process start time:

wmic process where Name="<process name>" get CreationDate

or

wmic process where ProcessID="<PID>" get CreationDate

You'll get a datetime like this: 20201021010512.852810+180.
Format: YYYYMMDDHHMMSS.ssssss+MMM(UTC offset)

If you want a more readable representation you'd need to prep it with a script. Here I have written a little batch script for the purpose:

@ECHO OFF
SETLOCAL

IF [%1]==[] (
    ECHO Prints process creation date in ISO format. 
    ECHO:
    ECHO USAGE: %~n0 ^<PID or Process name^>
    EXIT /B 1
)

IF [%~x1]==[.exe] (SET type=Name) ELSE (SET type=ProcessID)

FOR /F "tokens=1,2 delims==" %%a IN ('wmic process where %type%^="%~1" get CreationDate /value') DO (
    IF [%%a]==[CreationDate] SET proc_cd=%%b
)

IF DEFINED proc_cd (
    ECHO %proc_cd:~0,4%-%proc_cd:~4,2%-%proc_cd:~6,2%T%proc_cd:~8,2%:%proc_cd:~10,2%:%proc_cd:~12,2%
)

Feed it with a PID or a process name ending with .exe and it will output when the process was started. Caveat: If there are many processes with the same name it would output the time only for the last one started.

Slider2k
  • 21
  • 2