views:

115

answers:

3

I want to run a command and, when it's complete, have a record of the maximum memory use of the resulting process. For instance, I want something analogous to the 'time' command on Linux, where 'time foo' will run 'foo' and, when 'foo' exits, will print out the amount of CPU time that 'foo' took.

For my present application I need this to run on Windows, but if you know of a Linux-only program let me know too. (At the very least it'd be interesting, but it may also give me a lead to find a Windows equivalent.)

A: 

I don't know of a program that does this, but there are APIs.

If you're using .NET, use the Process.TotalProcessorTime property.

If you're using native code, use the GetProcessTimes() function.

itowlson
The problem with said APIs is that you have to continually poll the target process to get the information. If I have to I'll have no problem writing such a program, but I was hoping there's a better way.
No, you can call them after the process has exited. You just need to hang onto the Process object (.NET) or HANDLE (Win32) that you were given when you started the process. You can determine when the process ends by calling Process.WaitForExit (.NET) or waiting on the HANDLE using WaitForSingleObject (Win32) -- no polling required.
itowlson
Oh, that's great. I'll suppose that works with the GetProcessMemoryInfo function too. Thanks!
+1  A: 

You can, if you have Vista (maybe 7 too, not sure). Go to start -> control panel -> system and maintenance -> administrative tools -> Reliability and Performance Monitor -> Performance Monitor -> Create new watch (green + symbol) -> Process -> Working Set -> [select a process below] and press Ok. You can log this, etc.

Screenshot: http://www.freeimagehosting.net/image.php?912df44d75.jpg

Pindatjuh