[Dev] HOWTO write a daemon

M. Mueller dev@trilug.org
Thu, 23 May 2002 23:46:14 -0400


--------------Boundary-00=_2TJLW1WXNDY57GVJYCNH
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

On Thursday 23 May 2002 09:56 pm, Paul D. Boyle reputedly wrote:

> Under Unix (Linux) all processes automatically open three I/O streams,
> stdin, stdout, stderr, these are often closed in a daemon process.

So, you need alternatives to these services.

I make great use of the syslogger daemon.  I had to become aware of the 
klogger, or kernel logger daemon because it would generate useful information 
for me.  This led to needing an awareness of the logrotate function which led 
to needing an awareness of cron from a system point of view.  I "tail -f" the 
/var/log/messages file for long periods of time and found that logrotate 
changes the file handles so that the "tail -f" goes dead so to speak.  I've 
hacked a script that lets me quickly manage the tail function (script 
attached). I eventually learned how to manage the /etc/syslog.conf and syslog 
calls to define new log files associated with new facilities.  
Another capability that I think Brent Verner brought to my attention, and 
that I have not investigated yet, is the FIFO abilities of the Linux 
syslogger.  More at "man syslogd".

My daemons use AF_INET sockets for interprocess communication.  I tried 
several flavors of IPC (SystemV, AF_UNIX sockets).  And there are more IPC 
methods I did not try.  I've seen code that used disk files for IPC.  The 
Stevens book, "UNIX Network Programming, Volume 2, Second Edition: 
Interprocess Communications, Prentice Hall, 1999" was my primary resource. I 
use Python to write shell to daemon "communicators". 

My intent here is to dump a bunch of ideas to the list that you can pick 
through.  If there is further interest, I can provide code detail and system 
configuration detail as requested.

-- 
Mike Mueller
www.ss7box.com
--------------Boundary-00=_2TJLW1WXNDY57GVJYCNH
Content-Type: application/x-shellscript;
  name="Tail"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Tail"

IyEvYmluL3NoCgpwcyAtQyB0YWlsIHwgZWdyZXAgInRhaWwifCBjdXQgLWMgMS01ID4gdGVtcAoK
Y2F0IHRlbXAKCndoaWxlIHJlYWQgcGlkOyBkbwoJZWNobyBraWxsICRwaWQKCWtpbGwgJHBpZApk
b25lIDwgdGVtcApybSAtZiB0ZW1wCgppZiBbICQxID0gIm9mZiIgXTsgdGhlbiBleGl0CmZpCgp0
YWlsIC1mIC92YXIvbG9nL21lc3NhZ2VzICYKI3BzIC1heGoK

--------------Boundary-00=_2TJLW1WXNDY57GVJYCNH--