* Peter N Lewis <[EMAIL PROTECTED]>
> ps auxw | grep xxxx
>
> inevitably finds the search command unless you use a trick like the above,
> or:
>
> ps auxw | grep xxxx | grep -v grep
Or, utterly off topic, the clever regex method, which may run afoul of
quoting rules in certain shells, but is quicker to type:
ps auwwx | grep xxx[x]
I recommend ww on OS X, due to the long command names. More shell tips:
http://sial.org/howto/shell/
Leering back towards Perl, I often use psgrep.
#!/usr/bin/perl -w
#
# $Id: psgrep,v 1.7 2005/10/06 06:22:54 jmates Exp $
#
# The author disclaims all copyrights and releases this script into the
# public domain.
#
# Greps process list for matching patterns.
use strict;
my $match = shift || die "Usage: $0 pattern\n";
# if no metacharacters, dress up to my liking
# TODO need "literal" flag or "non-sensitive" options?
if ( $match =~ m/^ [\w-]+ $/x ) {
# do not like 'ssh' matching 'ssh-agent'
if ( $match eq 'ssh' ) {
$match = $match . '(?!(?:-agent|d))';
}
$match = '(?i)' . $match;
}
my @ps_cmd = qw(ps axwwo);
my @ps_options = qw(user pid command);
open PS_CMD, '-|'
or exec @ps_cmd, join( ',', @ps_options )
or remark( 'error', 'ps failed', { errno => $! } ) && exit 101;
while (<PS_CMD>) {
next if /^\s/;
chomp;
my %process;
@[EMAIL PROTECTED] = split /\s+/, $_, scalar @ps_options;
# skip "PID" (header data) or this process itself
next
if exists $process{pid}
and $process{pid} =~ m/\D/ || $process{pid} == $$;
next unless $process{command} =~ m/$match/o;
print join( ' ', @[EMAIL PROTECTED] ), "\n";
}