Windows マシンで実行中のプロセス (およびサービス) のリストを取得する最も標準的な方法を探しています。古いサーバーにそのプログラムを展開するので、「最新の」ものを使用しないことが重要です。
何か案が?
skp が述べたように、tasklist コマンドで実行できます (Windows XP でテスト済み)。
PID によってプロセスのハッシュを作成する小さなスクリプトを次に示します。
use warnings;
use strict;
my @procs = `tasklist`;
#Find position of PID based on the ===== ====== line in the header
my $pid_pos;
if ($procs[2] =~ /^=+/)
{
$pid_pos = $+[0]+1;
}
else
{
die "Unexpected format!";
}
my %pids;
for (@procs[3 .. $#procs])
{
#Get process name and strip whitespace
my $name = substr $_,0,$pid_pos;
$name =~s/^\s+|\s+$//g;
#Get PID
if (substr($_,$pid_pos) =~ /^\s*(\d+)/)
{
$pids{$1} = $name;
}
}
use Data::Dumper;
print Dumper %pids;
役立つかもしれない別のアプローチは、Win32::Process::List
. コア Windows C 関数を使用してプロセス リストを取得します。古いバージョンの Perl で動作するようです。