Skip Menu |

This queue is for tickets about the Win32-Process-Info CPAN distribution.

Report information
The Basics
Id: 36362
Status: resolved
Priority: 0/
Queue: Win32-Process-Info

People
Owner: Nobody in particular
Requestors: KES [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: Subprocesses returns sometimes wrong subprocesses
Begin from Wed May 21 14:46:30 2008 you can see that in Subprocesses hash there is unexpected tasks in log Sub processes relation is: msgLog( $context->{logFile}, localtime(). " Sub processes relation: ". Dumper( $pi->Subprocesses( $task->{PID} ) ) ); Or may be this is Win32 BUG =) BUG with that that when *.bat file is runned Win32 makes root process for current login (explorer.exe) as child of that batch file (*.bat) So when I stop my service it kills its subtasks and so kill root instance of explorer.exe and this is cause of closing all opened application. As result all unsaved data is lost (((
Subject: Copy of TAService.log

Message body is not shown because it is too large.

I have seen Windows do some strange things from time to time, but I would not expect it to re-parent explorer.exe. Nevertheless, subprocesses can be a little tricky. It appears that when Windows starts a process, it records as the parent the PID of the process that started it. Now, when a process exits, its subprocesses do not go away, and they continue to think the "dead" process is their parent. You could say they are orphans but do not know it. Worse than that, Windows re-uses process IDs, so if you go on PID alone (which I think Subprocesses() does), you can think that a new process having the same PID as the old process is your parent, when it really is not. Now, Subprocesses() simply walks through the system getting a list of PIDs and their parents, and matches them up. To get the true subprocesses, you should compare the start time of the parent to the start time of the subprocess, and reject any subprocesses that started before the parent. In fact, Subprocesses() should probably do this, but I just found out that was an issue. I do not understand how this mechanism could make explorer.exe appear to be a subprocess of your service, but it is a fact that, at the point you say the script goes wrong, you have explorer.exe with ProcessId 2292, CreationDate of 1211364961 (= Wed May 21 10:16:01 2008 UT), and ParentProcessId of 2188, though ProcessId 2188 is cmd.exe, started at CreationDate 1211370389 (= Wed May 21 11:46:29 2008 UT). So explorer.exe is clearly not a subprocess of cmd.exe, no matter what the PIDs say. So although I do not completely understand what is going on in your system, I do have some recommendations: Recommendation: Try comparing the CreationDate of the parent process to the CreationDate of the subprocess, and ignoring those apparent subprocesses that started before their parent processes. Please let me know if this helps. I may be able to develop a patch to Subprocesses() without Windows, since all it does is to match up process IDs. I will have to see what information is available in Subprocesses() to know what I can do in this area. Recommendation: There are system explorers (or whatever you call them) available that will give you a process hierarchy. There used to be an outfit called "System Internals" that had a program called "Process Explorer" that would do this for you. Currently their url redirects to http://technet.microsoft.com/en-us/sysinternals/default.aspx but "Process Explorer" still seems to be available. If there is some question about who is whose parent process, something like this would be helpful. Recommendation: If you could recode updateMemoryUsageStat() so that the calls to Subprocess() and GetProcInfo() were outside the "for" loop, the script that contains updateMemoryUsageStat() might run longer. This might complicate matters inside the loop a little, but you might get away with something like # Get the subprocess tree of the whole system. my $subprocs = $pi->Subprocesses(); # Make a hash for all the processes, keyed on PID my %proc_inf = map {$_->{ProcessId}, $_} $pi->GetProcInfo(); outside the loop, and then # Get all subprocesses of $task->{PID) (if that's what this does. my @procList = subprocessList($task->{PID}, $subprocs); # Get the process information for the desired processes. my @procsInfo = map {$proc_inf{$_}} @procList; The above assumes (at least!) that your subprocessList() does not care if there are extra items passed in the hash that is the second argument. I should have recommended this in response to the previous bug, but I confess that it was not until this bug that I investigated your sample code that thoroughly.
I have attached a copy of Info.pm with Subprocesses() modified to return a correct subprocess list. I hope. Would you mind terribly replacing your Info.pm with the new one, and letting me know if I have fixed the subprocess problem? Or broken something else? The file you replace should be somewhere under your Perl installation directory; the last few pieces of the filename should be Win32\Process\Info.pm. I would like to recommend that you rename the old Info.pm rather than deleting it, in case I messed something up badly. I would also like to recommend that you verify that I converted the file to DOS line endings. I THINK I did, but ...

Message body is not shown because it is too large.

Win32-Process-Info 1.012 has just been uploaded to CPAN. This contains the fix for the Subprocesses() method, and a new SubProcInfo() method, which calls GetProcInfo() and then adds to each process hash a {subProcesses} key containing the information for that process' subprocesses. It typically takes four to six weeks for CPAN uploads to make it into Active State's PPM repository. My last upload about a month ago still has not made it, which means either they are about to make a run, or they are running behind. In the meantime, people who can not wait for Active State can download the package from their favorite CPAN mirror, extract the .tar.gz file, convert the line endings to Windows (they're U*ix line endings in CPAN), and follow the instructions in the README file. I will watch Active State's PPM repository, and mark this case closed a decent interval after the new module reaches there, unless I get feedback to the contrary.
On Thu Jun 12 23:00:51 2008, WYANT wrote: Show quoted text
> > I will watch Active State's PPM repository, and mark this case closed a > decent interval after the new module reaches there, unless I get > feedback to the contrary.
Five months later, ActiveState puts up http://ppm4.activestate.com/. Since this update appears there, the criteria for closing the report have been met at long last.