4.1. How to Build a Daemon
This section shows you how to build a daemon and offers a brief explanation of why each step is needed. Your application may not require all of the steps listed, and you may need to do them in a different order to meet your needs, but this will give you a general idea, nonetheless.
Load the configuration.
Go into the background.
Become the process and session leader.
Set the working directory.
Redirect stdin, stdout, and stderr.
Set up logging.
Set group IDs and user IDs.
Check for a pidfile.
Set the umask.
Set up signal handlers.
Note:
The sample daemon presented later in this chapter includes code for each of these steps. Some of the following sections use code taken from the sample daemon.
4.1.1. Load the Daemon's Configuration ...
Get Linux Appliance Design now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.