#!/usr/bin/perl -w use strict; sub is_running { my $process = shift; # name of process my @p = grep { !/grep/ } `ps aux | grep $process`; # ps aux without the greps print @p; # comment this out return scalar @p; # false if @p is empty; true otherwise } # test program foreach (qw(httpd sshd syslogd telnetd ftpd yourmama)) { printf("$_ %s running.\n", (is_running($_) ? "is" : "is not")); }
w/ the experimental syntax-highlighted remix
#!/usr/bin/perl -w
use strict;
sub is_running {
my $process = shift; # name of process
my @p = grep { !/grep/ } `ps aux | grep $process`;
# ps aux without the greps
print @p; # comment this out
return scalar @p; # false if @p is empty; true otherwise
}
# test program
foreach (qw(httpd sshd syslogd telnetd ftpd yourmama)) {
printf("$_ %s running.\n", (is_running($_) ? "is" : "is not"));
}
In reply to Re: Searching strings within an array for a particular word.
by beppu
in thread Searching strings within an array for a particular word.
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |