perl查找进程PID的例子
巴扎黑2017-01-11 13:38:20513主要是利用查找/proc目录下的相关文件进行查找.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/usr/bin/perl
use strict;
use warnings;
exit ( main( @ARGV ) );
sub main {
my $Phash ;
my $ProcessName = shift ;
my $PROC_DIR = "/proc" ;
chdir $PROC_DIR ;
my @pids = glob "[0-9]*" ;
for my $pid ( @pids ) {
open ( FH, "$pid/cmdline" ) or die "Can't $pid file $!" ;
$Phash ->{ $pid } = $_ while <FH>;
}
DELETE $Phash ->{ "$$" };
for my $pid ( keys % $Phash ) {
print $pid , "\n" if $Phash ->{ $pid } =~ / $ProcessName /;
}
return 0;
}
|
更多关于perl查找进程PID的例子请关注PHP中文网(www.php.cn)其他文章!