|
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: Attempt to free non-existent shared
string ‘ExecQuery’ at (eval 1) line 1. Free to wrong pool 222518 not 22c758
at (eval 1) line 1. I’m using ActiveState Perl 5.8.4-810 on WinXP Pro SP2. Thanks. ------------------------------------------------------------------------- my $pid; my $RunChild; if ($pid = fork) { # parent here...wait a bit and signal
child sleep 5; kill HUP => $pid; print "Parent done...sleeping
another 5 seconds to wait on child\n"; sleep 5; exit(0); } elsif (defined $pid) { # this is the child...so, install signal
catcher to terminate child $SIG{HUP} = sub { $RunChild = 0; }; use Win32; use Win32::OLE qw(in); # 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 sends
signal to stop $RunChild = 1; while ($RunChild) { my $Computers =
$WMI->ExecQuery("SELECT * FROM Win32_OperatingSystem"); foreach $pc (in
($Computers)) {
foreach $object (in $pc->{Properties_})
{
print "$object->{Name} => \t $object->{Value}\n" if
($object->{Name} =~ /FreePhysicalMemory/);
} } sleep 1; } print "Child done now...Press
<ENTER> to finish"; getc(); exit(0); # so as not to
keep the child running } else { die "Can't fork: $^E\n"; } |
_______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
