Jugendzentrum Kirchheim - Technik![]()
daemon.pm
Simple Perl-Object to create daemons under Linux (and perhaps other Unix-like systems). The module detaches the process and makes sure that no more output is sent to the console. If you want to quit the daemon, you can use the kill function which will send the daemon a QUIT signal, causing it to quit properly.
A simple logging interface is provided, as well as a function to test whether the daemon is running (this function uses the the PID file).
We provide two examples for our daemon object, that should show the functionning principles for two main usages of backgroud processes:
Timer-controlled daemon
This program is a backgroud process that uses a timer to take regular
actions. Such an action could be writing an entry to a log file or checking
wheather there are new files in a directory. In place of a timer we abuse
the select function (which is usually needed for non-blocking IO; we have
to use it as it is the only portable way to have a timer which supports
times shorter than a second).
Server daemon
A small server program that prints out the local time to all clients that
connect to its listening address. The daemon sleeps while there is no
change on the listening socket (blocking IO).
The first step is usually to decide which kind of daemon you wish to write. Then you should have a look at a sample program (something like the two scripts you can download above). If you need a reference for the functions, have a look at the documentation contained inb the module: