easy question about kill command

Oliver Fromme olli at lurza.secnetix.de
Fri Dec 16 01:37:11 PST 2005


Roman Gorohov. <roma.a.g at gmail.com> wrote:
 > Thanks for your reply. My question was about standard bsd daemons, not
 > about some apps with unpredictable behaviour.

But the kill command doesn't know what kind of daemon it
is sending a signal to.  It just sends a signal to a PID.
That PID could belong to a daemon from the bases system
(such as mountd), or it could belong to a third-party
program (such as apache).  There is no way for the kill
command to know.

If a program is unable to perform an action (be it a
restart after receiving a SIGHUP or whatever), it is the
responsibility of the program to print or log a message.
I think most daemons in the FreeBSD base system do that.

For example, when you send a SIGHUP to a mountd process
and there's a fatal error in your /etc/exports file, the
fact is logged via syslog (by default it is written to
/var/log/messages).  For convenience you can write a
small shell script (or alias, or shell function) which
does this:  kill -HUP $1; sleep 3; tail /var/log/messages

Best regards
   Oliver

PS:  I wrote the following shell script for that purpose:

#!/bin/sh -
LOGFILE=/var/log/messages
LOGSIZE_BEFORE=$(stat -f%z $LOGFILE)
logger "Executing killall -HUP $*"
killall -HUP "$@"
sleep 3
LOGSIZE_AFTER=$(stat -f%z $LOGFILE)
tail -c $(( $LOGSIZE_AFTER - $LOGSIZE_BEFORE )) $LOGFILE

I named it "killhup".  I can then type "killhup mountd",
so it restarts the mountd process, then waits 3 seconds,
and then it prints any new messages from the log file
(or nothing if everything is OK).

-- 
Oliver Fromme,  secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing
Dienstleistungen mit Schwerpunkt FreeBSD: http://www.secnetix.de/bsd
Any opinions expressed in this message may be personal to the author
and may not necessarily reflect the opinions of secnetix in any way.

Python is executable pseudocode.  Perl is executable line noise.


More information about the freebsd-hackers mailing list