http://qs321.pair.com?node_id=759634

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

I am looking for a way to monitor if a process has stopped responding on a server, I cannot seem to find anything that will help me with this and I really need it, could someone please point me to something that I can use that will help with this? further information, Operating system is windows server 2003, process is mercury loadrunner, it spawns some subprocesses as well as the main executable which is called vugen.exe, namely mmdrv.exe and thumbprocess.exe occasionally it will hang (stop responding) and my scripts will stall. The purpose of the server is to monitor website performance of a custom application. I run the script on the server via remote desktop, I use windows script to restart the process if it has ended succesfully, the script itself in vuserend calls and executes a batch file using process.exe to kill itself then it calls a vbscript which is to restart the application and set focus and finally call a perlscript using win32guitest to get the window id and sendkeys to the application to restart it. I notice that thumbprocess.exe appears to be causing the hang, and if I kill it the application will sometimes start responding again. I am looking for a solution, I downloaded win32 process and win32 process info yesterday but am not sure what to do to solve this problem and was hoping for some guidance. I am reading about win32process info but I don't understand how to get anything out of it. I looked at planetscapes hash tutorial and now I am able to print out the info for a process but I am looking to do something with the information, which I am not clear on how to do with this module, any suggestions? oh and here is the code I have so far, I know its not much but it does at least display some info.
use Win32::Process::Info; use Data::Dumper; $pi = Win32::Process::Info->new (); $pi->Set (elapsed_in_seconds => 0); # In clunks, not seconds. @pids = $pi->ListPids (); # Get all known PIDs @info = $pi->GetProcInfo (); # Get the max %subs = $pi->Subprocesses (); # Figure out subprocess relationships. @info = grep {$_->{Name} =~ m/perl/} $pi->GetProcInfo (); # All processes with 'perl' in name. #print $info; #print $pi; foreach(@info) { print $_; } my $href=\%subs; print Dumper $href; print Dumper @info;

Replies are listed 'Best First'.
Re: monitor process
by Bloodnok (Vicar) on Apr 23, 2009 at 19:47 UTC
    You might consider elaborating further - self-evidently a remote process has stopped responding when a connection (of some sort) cannot be established with it aka it's stopped responding.

    For example, try identifying...

    • The protocol &/or port over which you're attempting communication
    • The OS at both ends of the connection
    • Whether the (behaviour of the) remote process is modifiable (in any way)
    • What you've tried thus far - in an attempt to reduce effort by eliminating repetition (of solutions you may have already tried)

    A user level that continues to overstate my experience :-))
Re: monitor process
by targetsmart (Curate) on Apr 23, 2009 at 19:51 UTC
    We generally used to check a process is alive by some methods.

    on *nix systems
    'top' command or ps command output
    kill -0 pid
    heart beats, this method will check the process is functional apart from alive status, heart beats are simple messages(usually program name+timestamp) will be sent to heart beat monitoring(hbm) server through socket, and the duty of the hbm server is to restart that process if no heart beats received for a configured amount of time.
    hope this helps


    Vivek
    -- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.
      I am able to connect to my process when passing in the process id which I obtained from processinfo.pl..(idea is to grab the new process id and pass it in and then use it to monitor process so it keeps running continuously or something.. ) process info code followed by my process.pl code which is just to connect and tell me exit code as I don't really know yet how to do anything with it. stuff below code is ignorable.
      use Win32::Process::Info; use Data::Dumper; $pi = Win32::Process::Info->new (); $pi->Set (elapsed_in_seconds => 0); # In clunks, not seconds. @pids = $pi->ListPids (); # Get all known PIDs @info = $pi->GetProcInfo (); # Get the max %subs = $pi->Subprocesses (); # Figure out subprocess relationships. @info = grep {$_->{Name} =~ m/vugen/} $pi->GetProcInfo (); # All processes with 'perl' in name. #print $info; #print $pi; my $href=\%subs; print Dumper $href; print Dumper @info; #print Dumper @pids;
      use Win32::Process; use Win32; sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Open($Obj,$pid=12732,$iflags)|| die ErrorReport(); print "connected to process $pid "; $Obj->GetExitCode($exitcode); print $exitcode;
      that sounds very much like what I want to do but how can I do it on a winblows system..(er I mean windows). I am looking at win32 process, but it's not clear how to export "still-active" I manage to get a bit over my head on this one,how do I explicitly export? so far I haven't gotten much, trying to figure out how to tell if still_active or setup a heartbeat or something. I can get it to launch but not to open my script.
      use Win32::Process; use Win32; sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Create($ProcessObj, "C:\\program files\\Mercury\\LoadRunne +r\\bin\\vugen.exe", "E:\\Mibor_timingtest\\Mibor\\mibor.us +r", 0, NORMAL_PRIORITY_CLASS, ".")|| die ErrorReport(); Win32::Process::Open($Obj,$pid=11672,$iflags)|| die ErrorReport(); $ProcessObj->Suspend(); $ProcessObj->Resume(); $ProcessObj->Wait(INFINITE);
      I am trying to figure this out has anyone used before? I get 259 as my exit code what does that mean?
      use Win32::Process; use Win32; sub ErrorReport{ print Win32::FormatMessage( Win32::GetLastError() ); } Win32::Process::Open($Obj,$pid=11672,$iflags)|| die ErrorReport(); print "connected to process $pid"; #$ProcessObj->Suspend(); #$ProcessObj->Resume(); #$ProcessObj->Wait(INFINITE); $Obj->GetExitCode($exitcode); print $exitcode;
Re: monitor process
by graff (Chancellor) on Apr 24, 2009 at 02:16 UTC
    If you are talking about checking a process on a "remote" server from some sort of "local" machine, and if you can run a login shell on the server (esp. if you can do "ssh that.server" from your local machine), and if both machines are *n*x or have gnu tools on them (lots of "ifs" there -- the OP leaves a lot to the imagination), then you could do something like:
    ssh that.server ps -flags | grep that_process
    Note that you'll need to be careful about choosing the "ps" option flags -- seems like no two flavors of *n*x use the same option definitions for "ps" these days. Just run "man ps" on that.server and read the output.
      Hmmm ,

      That's all very well, graff, but it can only identify the situation whereby the remote server process has stopped running.

      I'm guessing, since the OP hasn't (yet) responded to a couple of requests for further information, that the OP has encountered the situation whereby the process appears to be running but is no longer responding to connection requests...hence either the heartbeat or polled approach (as mentioned elsewhere) would be the logical solution.

      A user level that continues to overstate my experience :-))
Re: monitor process
by zwon (Abbot) on Apr 23, 2009 at 20:33 UTC

    You can just periodically send test requests to the server. If you elaborate a bit more on your problem you probably would get a better answer.