Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Detecting hung conditions in win32

by Zadeh (Beadle)
on Feb 21, 2006 at 18:08 UTC ( [id://531754]=perlquestion: print w/replies, xml ) Need Help??

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

I'm trying to write a perl script in windows that will use windows devenv.com command to automate the building of .sln and .vcproj files. Problem is, some of them have custom build steps at the end which launches a test--which sometimes will hang.

So, I'm trying to figure out a way to detect that. My first thought was to try forking a child and communicating with a pipe, but open(FH, "-|") doesn't appear to work in windows, and I'm not sure how to detect a hung state. Thoughts?

Replies are listed 'Best First'.
Re: Detecting hung conditions in win32
by GrandFather (Saint) on Feb 21, 2006 at 18:39 UTC

    Take a look at Win32::Process, especially GetExitCode($exitcode) and Wait($timeout).


    DWIM is Perl's answer to Gödel
Re: Detecting hung conditions in win32
by BrowserUk (Patriarch) on Feb 21, 2006 at 21:06 UTC

    I'd suggest looking at Win32::Process::Info. Start the process and use W::P::I to monitor it's process utilisation . If it fails to change over a period of a few seconds, it is either waiting for input or is hung. Your program logic should allow you to distinguish the difference.

    See Re: Win32: Multiple processes with the same name and Re^3: Win32: Multiple processes with the same name for some sample code.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Detecting hung conditions in win32
by jdhedden (Deacon) on Feb 21, 2006 at 18:36 UTC
    Try using alarm inside an eval:
    eval { local $SIG{'ALRM'} = { die("Timeout\n"); }; alarm(60); system('build.sh'); alarm(0); }; if ($@ =~ /^Timeout/) { die("Build timed out\n"); }

    Remember: There's always one more bug.
      Thanks, but a problem there is that it doesn't really detect the hung state, but kills it after a set amount of time (60 seconds), right?
Re: Detecting hung conditions in win32
by eyepopslikeamosquito (Archbishop) on Feb 21, 2006 at 20:54 UTC

    As described in Re: Timing Windows commands, I like to use the Win32::Job module (comes standard with ActivePerl, requires Windows 2000 or later) for this sort of thing.

Re: Detecting hung conditions in win32
by Anonymous Monk on Feb 22, 2006 at 02:14 UTC

    If it's Win32, it's probably hung.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://531754]
Approved by Tanktalus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-28 08:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found