Question

I am using ps -C <executable name> on Linux, but the same does not work on Windows.

How can I perform the same check in Perl so that it is platform independent?

Was it helpful?

Solution

You might be able to use Win32::Process::List

use 5.12.0;
use warnings;
use Win32::Process::List;

my $P = Win32::Process::List->new();
if($P->IsError == 1) {
    die $P->GetErrorText;
}

my %list = $P->GetProcesses();
foreach my $key (keys %list) {
    # $list{$key} = process name, $key=PID
    say sprintf("%25s %10s", $list{$key}, $key);
}

And process appropriately.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top