in reply to Equal strings don't match!
On my system, stuff read from /proc/*/cmdline comes complete with a trailing null character (chr 0) and also nulls separating the command from its arguments. I might rewrite your code this way:
use strict; use warnings; opendir my $proc_dh, '/proc' or die "Can't opendir '/proc': $!"; my @every_pid = grep /\d/, readdir $proc_dh; closedir $proc_dh; chomp @every_pid; my @every_cmd; foreach my $pid ( @every_pid ) { open my $cmdline_fh, '<', "/proc/$pid/cmdline" or die "Can't open '/proc/$pid/cmdline': $!\n"; my ($cmd) = split /\0/, scalar <$cmdline_fh>; push @every_cmd, $cmd if defined $cmd; close $cmdline_fh; } if ( grep { '/usr/sbin/sshd' eq $_ } @every_cmd ) { print "found\n"; } else { print "not found\n"; }
Notice that,
I would point out also that you may be able to say "ps -C sshd" at your command prompt and find out what you want.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Equal strings don't match!
by pl (Initiate) on Jul 30, 2008 at 18:44 UTC | |
by kyle (Abbot) on Jul 30, 2008 at 18:59 UTC | |
by pl (Initiate) on Jul 30, 2008 at 19:16 UTC | |
by AltBlue (Chaplain) on Jul 31, 2008 at 02:13 UTC | |
by pl (Initiate) on Jul 30, 2008 at 18:54 UTC |