DAEMON(8)

NAME
daemon - run a job in the background, restarting it when it terminates

SYNOPSIS
daemon [ -l lockfile ] command [args]

DESCRIPTION
daemon Is useful for daemonising a process that isn't already set up to be a daemon (like, for example, a ppp script that you're using to keep a network connection active.) When you invoke it, it starts a daemon process that repeatedly executes the process you want, then prints the process ID of that daemon and exits. You may then use that process ID for signalling the daemon - the daemon detaches from the controlling tty, so you can later kill it and (hopefully) all of it's children.

If you do not redirect input and output away from a tty device, it is redirected to the device /dev/null; so this is not a good script to use for controlling getty processes.

To attempt to kill the process, simply send a HUP, TERM, QUIT, or INT signal to the daemon process, and it will relay this signal to the command, then exit after the command terminates. The KILL signal is caught as well, but since this signal is uncatchable it doesn't do much good.

The USR1, USR2, PIPE, ABRT, TRAP, FPE, and ALRM signals are also caught by the daemon process, but they are summarily ignored.

If you specify a lockfile on the commandline, daemon will attempt to write its process-id into that lockfile before it runs; if the lockfile already exists, it will check and see if the program owning the lock is still in existance, and it will overwrite the lock if the program is no longer around.

NOTE
The pid of the daemon process should also be the process group of that daemon after it's detached itself from the controlling tty. A kill(-pid,sig) should send the signal to every process in that group.

EXAMPLE
$ daemon telnetd
500
(make sure that telnetd is doing what it should)
$ kill -HUP 500
(telnetd should be dead now)

AUTHOR
David Parsons - orc@pell.chi.il.us

SEE ALSO
go(8)