abstract:主要是利用查找/proc目錄下的相關(guān)文件進(jìn)行查找.#!/usr/bin/perl use strict; use warnings; #usage: process_grep.pl ProcessName exit( main(@ARGV) ); sub main {
主要是利用查找/proc目錄下的相關(guān)文件進(jìn)行查找.
#!/usr/bin/perl use strict; use warnings; #usage: process_grep.pl ProcessName 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; }
更多關(guān)于perl查找進(jìn)程PID的例子請關(guān)注PHP中文網(wǎng)(m.miracleart.cn)其他文章!