Excluding grep from process list

ps aux | grep daemon_name | awk "{ print $2 }"

grep’s -v switch reverses the result, excluding it from the queue. So make it like:

ps aux | grep daemon_name | grep -v grep | awk "{ print $2 }"

Upd. You can also use -C switch to specify command name like so:

ps -C daemon_name -o pid=

The latter -o determines which columns of the information you want in the listing. pid lists only the process id column. And the equal sign = after pid means there will be no column title for that one, so you get only the clear numbers – PID’s.


Tags: , , , , , , , ,