[sf-lug] shell tip: ps ... | grep ... | grep -v grep
Michael.Paoli at cal.berkeley.edu
Fri Jul 4 12:04:53 PDT 2008
While typical Linux distributions have pidof, for greater (e.g.
UNIX/BSD) portability, often something like:
ps args | grep 'pattern' | grep -v grep
is rather commonly used ... e.g. to find the PID(s) running a particular
Well, a bit more efficient approach would typically be:
ps args | grep '[p]attern'
How does it work? Well, the RE [p]attern will match pattern, but the ps
line with grep won't match RE [p]attern, as it will have literal
argument [p]attern, and thus won't match RE [p]attern.
Hans Peter Verne, Daniel Robbins
More information about the sf-lug