linux - Prevent process from killing itself using pkill -
i'm writing stop routine start-up service script:
do_stop() { rm -f $pidfile pkill -f $daemon || return 1 return 0 }
the problem pkill (same killall) matches process representing script , terminates itself. how fix that?
you can explicitly filter out current pid results:
kill $(pgrep -f $daemon | grep -v ^$$\$)
to correctly use -f
flag, sure supply whole path daemon rather substring. prevent killing script (and eliminate need above grep
) , killing other system processes happen share daemon's name.
Comments
Post a Comment