Darrin Barr wrote:
> I’m trying to create a memory monitor process that is running as a
> forked child while the parent rolls merrily along doing stuff. The idea
> is for the main thread to do fancy processing on some data while the
> child process keeps track of memory usage, threads, etc. When the main
> thread of processing is complete, it signals the child process to stop
> monitoring and to write some summary data. I’ve experimented with WMI
> and Win32::Perflib. WMI gives me the info I want, but causes a crash;
> Win32::Perflib doesn’t have all the data I want.
>
>
>
> Below is a simplified example that demonstrates my problem. When the
> forked child terminates, the perl interpreter crashes. If I let the
> parent exit (which takes down the child), the perl interpreter crashes
> with the following error:
Try using process create instead of fork (I added a time check in the child
in case kill should fail) :
use strict;
use Win32;
use Win32::OLE qw(in);
use Win32::Process;
use Time::HiRes qw(gettimeofday tv_interval);
if (@ARGV) {
# connect to Windows Management Instrumentation Server
my $Computername = Win32::NodeName();
my $WMI = Win32::OLE->GetObject("WinMgmts://$Computername") or
die "Can't connect to Windows Management Instrumentation server: $^E\n";
# start monitoring until parent kills us or n seconds of execution
my $t0 = [gettimeofday ()];
while (1) {
my $Computers = $WMI->ExecQuery(
"SELECT * FROM Win32_OperatingSystem");
foreach my $pc (in ($Computers)) {
foreach my $object (in $pc->{Properties_}) {
print
"$object->{Name} => \t $object->{Value}\n" if
($object->{Name} =~ /FreePhysicalMemory/);
}
}
sleep 1;
my $elapsed = tv_interval ($t0);
if ($elapsed > 15) {
print "Child exiting\n";
exit;
}
}
} else {
my $Obj;
Win32::Process::Create($Obj, $^X, "$^X $0 child", 0, 0, '.') or
die "Win32::Process::Create: $!";
sleep 10;
print "Parent killing child\n";
$Obj->Kill(2);
print "Parent exiting\n";
exit;
}
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs