开发者

What is the equivalent of ps command in perl?

开发者 https://www.devze.com 2023-04-04 14:11 出处:网络
I am using ps -C <executable name> o开发者_JS百科n Linux, but the same does not work on Windows.

I am using ps -C <executable name> o开发者_JS百科n Linux, but the same does not work on Windows.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消