2
1
I have a batch file that calls an external program that periodically hangs. What I would like to do is set a time limit on the batch file / CMD prompt such that it automatically closes after a certain period of time. One catch is that the external program that hangs may have one or more instances running at a given time, and I only want the batch file hitting its time limit to close the instance of the program triggered by the batch. How can I accomplish this? Ideally a solution would work on Windows XP, Vista, and 7.
1This does not discriminate for the instance started by the batch file. And status not responding might only work for GUI programs. – Joey – 2012-06-27T11:36:56.533
touché about the instance.. the status would work for everything..it is basically status you see in task manager....if that status is "running" and still program hangs, i doubt there is any way to detect the hang... – tumchaaditya – 2012-06-27T11:41:08.123
Well, the not responding one would be detected by the window manager when a program cannot process events in its message queue. But that requires a window and I've never seen console programs "hang" in that fashion. Presumably because the console host process never hangs and the program running inside never talks with the WM directly. – Joey – 2012-06-27T11:45:06.617
In this case the process is still "running" per the task manager, but it has suffered a network timeout and it just sitting there waiting for the user to see and deal with it. In this case, as I don't want the user to see/deal with that, I'm okay with just indiscriminately killing the process every few hours (it recovers gracefully enough). As Joey pointed out, it will kill all of the processes with the same name rather than the one I just started. I see that taskkill has an option to kill by PID, but I don't know how to get the PID of an instance when I launch it. – russellpierce – 2012-06-27T17:32:20.227