perl查找进程PID的例子
时间:2021-03-24 10:30:38|栏目:perl|点击: 次
主要是利用查找/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
下一篇:Windows10下安装配置 perl 环境的详细教程
本文标题:perl查找进程PID的例子
本文地址:http://www.codeinn.net/misctech/87236.html