1 Writing daemon Basic rules
1) umake (0) Set the file mode creation screen Word to 0
2) after fork, the parent process exit
3) Child process call Setsid
4) Change the working directory ChDir ("/")
5) Close all open file descriptors
6) Open file descriptor on/dev/null
2 Daemon Process error handling
Three ways to generate log messages:
1) kernel process Call log function write log message to/dev/klog
2) User process calls Syslog function write log message to/dev/log
3) The process on the network host sends a log message UDP packet to 514 port
The syslogd daemon is used to process log messages, and the profile for this process is typically/etc/syslog.conf, which determines how different kinds of messages should be handled
#include <syslog.h>void openlog (constchar *ident,int option,int facility) void syslog (int priority,constchar *format,...) void Closelog (); int setlogmask (int maskpri)
Ident is typically the program name and will be added to each log message
13th Chapter The Guardian process summary