27

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

1
34

Using the Powershell Get-Process cmdlet:

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

7
  • 7
    interestingly - not all processes have a starttime – warren Oct 5 '15 at 19:29
  • 10
    @warren - run it as Administrator and all services have a time. – disasteraverted Aug 30 '16 at 5:08
  • @Davidw, What about batch command? – Pacerier Dec 26 '16 at 3:33
  • This won't account for the amount of time the computer was in hibernation since the process started. – BenVlodgi Dec 27 '16 at 8:02
  • @disasteraverted I am running PowerShell ISE as administrator on a WIndows Server 2012 R2, NO, all processes do not have starttime. – TheCrazyProgrammer May 10 '17 at 22:41
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.

1
  • 2
    Process Explorer solves the problem. – SparedWhisle May 27 '15 at 2:20
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy