perl查找进程PID的例子
主要是利用查找/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; }
相关推荐
liujiaoyage 2020-09-09
山有木兮卿有意 2020-06-25
Attend 2020-06-14
citic 2020-06-14
wandererdl 2020-06-14
lfjjia 2020-04-19
ajuan 2020-03-03
wangrui0 2020-02-20
LczPtr 2020-02-14
fcds00 2020-01-28
DonviYang 2020-01-08
Happyunlimited 2020-01-01
学习备忘录 2019-12-08
batoom 2011-03-06
pwl 2008-06-13
IsanaYashiro 2019-11-05
hehuistudent 2008-09-11