use Win32::Process; use Win32::Process::Info; use Win32::Exe; use Devel::Leak; sub cmd_processes { my $pi = Win32::Process::Info->new(undef, 'NT'); my $response = { action => 'processes', }; for($pi->ListPids) { my ($info) = $pi->GetProcInfo($_); next unless ($info && defined($info->{ProcessId})); if ($info->{ExecutablePath}) { my $sigalrm = $SIG{ALRM}; eval { $SIG{ALRM} = sub { die "cmd_processes item exe timeout\n"; }; alarm(1); my $exe = Win32::Exe->new($info->{ExecutablePath}); alarm(0); foreach my $var (qw/CompanyName FileDescription FileVersion InternalName LegalCopyright LegalTrademarks OriginalFilename ProductName ProductVersion/) { $info->{$var} = $exe->version_info->get($var); } undef($exe); }; $SIG{ALRM} = $sigalrm; } push(@{$response->{process}}, $info); undef($info); } undef($response); undef($input); } for (1..10) { my $handle; my $count = Devel::Leak::NoteSV($handle); print "\nPRE: $count\n"; cmd_processes(); $count = Devel::Leak::NoteSV($handle); print "POST: $count\n"; }