trala has asked for the wisdom of the Perl Monks concerning the following question:

Oh ye monks, bestow your wisdom upon me.

I am launching an external program through perl on Windows. Most of the time, everything goes well. But sometimes, the program decides to throw up a click-through error message. I don't want to babysit the script - if the program hangs, kill it and return an error. I could timeout the process, but there is no good way to know how long it will take - it varies on a case by case basis. So I thought maybe I could check every so often and see how much CPU resources the process is using... then if it stops using the CPU for a while, kill it. Is there a way to check CPU resources based on a process ID? Or maybe there is a better way to do this?

Thanks in advance, Laura

Replies are listed 'Best First'.
Re: Kill a process if it hangs
by perrin (Chancellor) on May 15, 2002 at 16:21 UTC
      what I meant to say, is that I have been looking at Win32::PerfLib... I don't see anything in Win32::Process that allows me to evaluate the CPU load. I found a sample script that displays the % processor time on the specified computer, but I cannot understand what it is actually doing...
      yes, I have been staring at this for hours ... I am still trying to wrap my mind around all the multi-layered hashes.
Re: Kill a process if it hangs
by thunders (Priest) on May 15, 2002 at 20:07 UTC
    Sysinternals has some command line tools for Win9x as well as WinNT/2000 of special interest is the PStools which is the best set of command line Win32 Process tools i've come across(the Pslist tool may be of interest to your problem set). Obviously this is not a Pure Perl solution so you'd need to make system calls or use backticks, but I've had success with these tools.