Subject: | Programm crashes while using Win32::Process::Info |
Programm need to work 24 hours 7 days per week but it can not... it
crashes after 5-6 hours =(
I am calculating memory usage and this code is runned every 5 seconds
The daemon runned as service with help of module: Win32::Daemon
sub updateMemoryUsageStat {
my( $context )= @_;
my $pi = Win32::Process::Info->new();
foreach my $task ( @{ $context->{tasks} } ) {
my $usage= {
VirtualPeak => 0,
PhysicalPeak => 0,
};
my $children= $pi->Subprocesses( $task->{PID} );
my @procList= subprocessesList( $task->{PID}, $children );
my @procsInfo= $pi->GetProcInfo( @procList );
for my $procInfo ( @procsInfo ) {
$usage->{VirtualPeak}+= $procInfo->{PeakVirtualSize};
$usage->{PhysicalPeak}+= $procInfo->{PeakWorkingSetSize};
}
$usage->{VirtualPeak}/=1024*1024;
$usage->{PhysicalPeak}/=1024*1024;
}
sub subprocessesList {
my( $currPid, $children )= @_;
my @processes= ( $currPid );
foreach my $pid ( @{ $children->{$currPid} } ) {
push @processes, subprocessesList( $pid, $children );
}
return @processes;
}
sub Callback_Running {
my( $event, $context ) = @_;
#if( SERVICE_RUNNING == Win32::Daemon::State() ) {#Perl 5.8
if( $event == 4128 ) { #Perl 5.10
updateMemoryUsageStat( $context );
}
return undef;
}