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

I recently upgraded one of my Win2K servers to Win2K3. After the upgrade, the Win32::Process module appears to be slightly broken in that it does not properly state the current process state. I have posted the issue with active state (who as far as I know supplied this module) but until there is a fix, I need to find another solution for tracking process state. The following example demostrates the issue:
my($exitcode,$junk,$process,$process2,$process3); use Win32::Process; #create a notepad process Win32::Process::Create( $process, "c:\\winnt\\system32\\notepad.exe", "", 0, NORMAL_PRIORITY_CLASS, '.', ) or die "Could not start process\n"; #get the processid $procid=$process->GetProcessID(); print "PROCID: $procid\n"; #open the procid and get the exit code if(Win32::Process::Open($process2,$procid,0)==1){ Win32::Process::Open($process2,$procid,0); $exit=$process2->GetExitCode( $exitcode ); print "EXIT for PROCID-$procid: $exit\n"; print "Enter to continue\n"; }else{ print "ProcessID $procid not running\n"; } $junk=<STDIN>; #ok, kill the process $process->Kill( $exitcode ); print "$procid Process Killed\n"; print "Enter to continue\n"; $junk=<STDIN>; #now get the procid and exit code again if(Win32::Process::Open($process3,$procid,0)==1){ Win32::Process::Open($process3,$procid,0); $exit=$process3->GetExitCode( $exitcode ); print "EXIT for PROCID-$procid: $exit\n"; }else{ print "ProcessID $procid not running\n"; } exit;
Under Win2K, this should show the following after opening and closing notepad:
PROCID: 1016
EXIT for PROCID-1016: 1
Enter to continue

1016 Process Killed
Enter to continue

ProcessID 1016 not running
However, on my Win2k3 systems, it is doing the following:
PROCID: 1980
EXIT for PROCID-1980: 1
Enter to continue

1980 Process Killed
Enter to continue

EXIT for PROCID-1980: 1 
Even though it *is* properly killing the notepad processID, it still seems to think it is openable with the module.

Now, all I need to do is have the script kick off a process that will eventually end on its own (it does not need killed) and check in to see if that process is still running every 10-15 seconds. (ie, all I really want is to know when Win32::Process::Open($process3,$procid,0)==0 ). I do not have a way to have that external process mark a file while it's running, so that is not an option. Is there another module I can use to check for a running process by process ID under Win32?
  • Comment on Another method of tracking process state in Win32? Win32::Process slightly broken on Win2k3
  • Download Code

Replies are listed 'Best First'.
Re: Another method of tracking process state in Win32? Win32::Process slightly broken on Win2k3
by Anonymous Monk on Nov 26, 2003 at 04:46 UTC
    The module may need to be recompiled, so try that