圆月山庄资源网 Design By www.vgjia.com

主要是利用查找/proc目录下的相关文件进行查找.

#!/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;
}

标签:
perl,查进程PID

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com