Structure of a Daemon

Structure of a Daemon
Daemons typically have the same structure, regardless of their functionality. A daemon starts off by initializing its variables. It then sets its IPC interface up, which could simply be signal handlers. The daemon then executes its body, which is almost always an infinite loop.

Most daemons start off by forking. Forking is a method that allows a process to clone itself, creating an identical child. A daemon, as a parent process, usually forks off and terminates (or dies), while its child is left executing the main loop. The child is usually called an orphan process. In Unixes, orphan processes are automatically adopted by the "init" process, and this action is known as re-parenting.

For a more practical approach, the following sections dissect the two previously mentioned daemons. Links to their sources are found at the end of the tutorial

No comments:

Top Blogs