You can use pgrep as long as you include the -f options. This makes pgrep match keywords in the entire command (including arguments) instead of the process name.
pgrep -f keyword
On the man page:
-f Typically, a pattern is mapped only to a process name. When -f installed, the full command line is used.
If you really want to avoid pgrep, try:
ps -ef | awk '/[k]eyword/{print $2}'
Note the [] around the first letter of the keyword. This is a useful trick to avoid matching the awk command itself.
Shawn Chin Nov 14 '11 at 10:41 2011-11-14 10:41
source share