Is there any simple way to show how long a specific PID instance has been active?
-
Here too: http://superuser.com/q/772815/78897 – Pacerier Dec 26 '16 at 03:34
3 Answers
Using the Powershell Get-Process cmdlet:
Get-Process | Select-Object id, starttime, name | Sort-Object id
- 1,210
- 3
- 14
- 24
-
7
-
10@warren - run it as Administrator and all services have a time. – disasteraverted Aug 30 '16 at 05:08
-
-
This won't account for the amount of time the computer was in hibernation since the process started. – BenVlodgi Dec 27 '16 at 08: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
-
Infact, I do not get starttime for any of them if I do `Get-Process` – TheCrazyProgrammer May 10 '17 at 22:43
-
You have to specify that object property, it is not visible by default, that's why the Select-Object part of the command. – Davidw May 17 '17 at 02:05
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).
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.
- 32,352
- 26
- 126
- 188
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.
- 21
- 2