Isolate Daemons From Terminals

Daemon processes can be affected by the terminal they were started from. Consider the following daemon startup script:

 echo "Starting Console Log Daemon"
 osmcat  /dev/osm > /var/spool/console &
If this script is started from a terminal (other than the console), problems can arise when the person who started it logs off, hits break or when osmcat tries to write to standard error (or to read from standard input) after the user starting logs off.

Therefore:

Isolate daemon processes from terminals. If osmcat is badly designed, all of the following safeguards are necessary to ensure it functions correctly when started from a terminal:

 echo "Starting Console Log Daemon"
 trap '' 1 2 3 15
 osmcat  /dev/osm > /var/spool/console 2>/dev/console </dev/null &

Notes: These techniques are also relevant to other languages, but such startup scripts are most commonly written in Shell.

The nohup(1) tool handles only the HUP (1) and TERM (15) signals.


When starting a daemon you can use setpgrp instead of nohup. This will disconnect the daemon from the controlling terminal by giving it its own process group (unfortunately the setpgrp command is not always documented).

e.koenders@lucent.com


CategoryUnixShellPattern


EditText of this page (last edited May 13, 2005) or FindPage with title or text search