I'm writing a stop routine for a start-up service script:
rm -f $PIDFILE
pkill -f $DAEMON || return 1
You can explicitly filter out the current PID from the results:
kill $(pgrep -f $DAEMON | grep -v ^$$\$)
To correctly use the
-f flag, be sure to supply the whole path to the daemon rather than just a substring. That will prevent you from killing the script (and eliminate the need for the above
grep) and also from killing all other system processes that happen to share the daemon's name.