I want to write a script which can run as a Windows service. It would restart a process active in the process tabl开发者_如何学JAVAe when the user is using the process and it exceeds for example 500mb of RAM. How can I do this? Can someone suggest any example?
There's always the dirty way. Using tasklist
in Windows:
use List::Util qw<first>;
my ( $mem )
= map { ( my $a = $_ ) =~ s/,//g; $a }
grep {; length }
map { m/([\d,]+)[ ]K$/ }
first { m/^perl\.exe\s+$$\b/ }
`tasklist`;
if ( $mem > MAX_MEM ) {
do_something();
}
But as I understand it, you could also do it like this, with Win32::Process::Info
:
use Win32::Process::Info;
my $pi = Win32::Process::Info->new ();
my $set = first { exists $_->{WorkingSetSize} } $pi->GetProcInfo( $$ );
my $mem = $set && $set->{WorkingSetSize};
精彩评论