1.

Solve : track a process running time?

Answer»

Any commands or code could track a process running time within a batch file?

When I RAN iteration of a process in Windows XP, a single process sometimes takes 100 HOURS (very rare, 1 of 50 iterations), and normally it shall take 1-2 minutes. It is a convergence problem in MCMC and I can not control it.

As an alternative, In my code, I can invoke OS batch file. If I could track a process running time, I can kill it with taskkill after a given time, such as 10 minutes.

I think it may work as:

1) sleep 0.5 seconds till a process start to run,

2) start to track the process running time,

3) if the process is done in 10 minutes, then END; else kill it.

Really appreciate your suggestions.

C:\batch>type kill10.bat

Code: [Select]rem C:\batch>sleep

rem Arguments are: Sleep <seconds>

rem www.tricerat.com

@echo off

sleep 600

Rem From tasklist:
rem notepad.exe 2192 Console 0 548 K

taskkill /pid 2192

OUTPUT:


C:\batch>kill10.bat


SUCCESS: Sent termination SIGNAL to the process with PID 2192.

C:\batch>Quote from: gnomegordon on January 18, 2010, 06:55:38 PM

Any commands or code could track a process running time within a batch file?

I can no longer modify (edit ) post #1. The modify key is not available.

The following batch finds the pid number and a COMMAND line argument allows the name of any process or application.


C:\batch>type kill10.bat

Code: [Select]@echo off

sleep 600


tasklist | findstr "%1" > notepid.txt


for /f "tokens=1,2 delims= " %%i in (notepid.txt) do (
echo pid=%%j

taskkill /pid %%j

)
Output:

C:\batch>kill10.bat notepad

pid=2284
SUCCESS: Sent termination signal to the process with PID 2284.
C:\batch>


Discussion

No Comment Found