The startup scripts on most Linux distributions handle this, by saving the Process ID of the service (daemon) when they launch it.
These PIDs are typically stored in
/var/run/. For example on my system Apache2 stores it original or parent process ID (useful for pre-forked processes) in
/var/run/apache2.pid. So you can then send signals such as
SIGSTOP to the process to signal either a configuration reload or to stop the service (daemon).
One note to help with your
ps ax style process searching is to use a little trick to escape the grep's regular expression pattern used for matching, such that it doesn't match itself. E.g.
ps ax | grep [a]pache2 | wc -l
man test gives you the basics of the
test command. For simple tasks in shell scripting, it best to avoid being dependent on which shell you are using. Normally for basic scripting, writing scripts targeting the Borne Shell (
/bin/sh) is recommended, as this tends to be the most popular lowest common denominator.
RC= `ps ax | grep [a]pache2 | wc -l`
if [ $RC -gt 0 ]; then
kill -SIGSTOP `cat /var/run/apache2.pid`