Monitoring the wall time of a process on windows?

2

Windows Task Manager has the ability to show the current CPU time of any given running process on windows, is there any way (not necessarily through Task Manager) to get the current wall time of a process?

An example, let's say I have a script that reliably runs for about 45 minutes. Without adding a progress bar to the script, is there any way to figure out for how long it has been running?

The math behind this seems pretty straight forward;

WallTime = CurrentWallTime - WallTimeProcessStarted.

Likewise, since the math is so simple, is there anyway to get the time that a process was started at?

Sean Madden

Posted 2012-10-19T16:41:45.113

Reputation: 131

1Try Microsoft SysInternal's Process Explorer. It gives you process start time, the time spent in user mode and kernel mode. – Ganesh R. – 2012-10-19T16:51:49.110

"Wall time"? Is that English? You may want to edit the Q. title, or at least lead off with a definition of that phrase. – kreemoweet – 2012-10-19T20:44:10.870

Both "wall clock time" and (less popular) "wall time" are common idioms in the US to mean time as experienced by human observers watching a clock on the wall. – Nicole Hamilton – 2012-10-19T21:44:43.567

Answers

2

Sure. Total elapsed time is available via the performance section of the registry and via the Toolhelp API. And of course, if you have the elapsed time and the current time, you can compute the start time.

There are two ways to retrieve the information via Win32, but neither one is particularly simple. The way that's been supported since the earliest releases of WinNT is to use RegQueryValueEx to parse first the list of available counters in HKEY_PERFORMANCE_DATA, then retrieve the ones you want on the process instances of interest. A newer way is to use CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS ), which got introduced with WinXP.

There are probably lots of apps that can do this, so you're inviting a list I'm sure others can add to. Here's how I did it in my C shell. ps -s lists all the system processes. The uptime sample utility calculates how long the system has been up from the elapsed time reported by ps -s for the Idle process.

Hamilton C shell ps utility reporting elapsed times for system processes

(The active time for Idle is simply the odd value reported by Win7.)

Nicole Hamilton

Posted 2012-10-19T16:41:45.113

Reputation: 8 987

1

If you're willing/able to use Python, there's something called psutil which would probably work. Alternatively, you can download its source code and see what Windows API calls it's using to provide the information.

martineau

Posted 2012-10-19T16:41:45.113

Reputation: 3 849