Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Searching strings within an array for a particular word.

by beppu (Hermit)
on Mar 06, 2002 at 01:41 UTC ( #149585=note: print w/replies, xml ) Need Help??


in reply to Searching strings within an array for a particular word.

How's this?
#!/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"));
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://149585]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2021-09-19 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?