Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages

Manual Reference Pages  -  ANY::DAEMON (3)

.ds Aq ’


Any::Daemon - basic needs for a daemon



  use Any::Daemon;
  use Log::Report;

  # Prepare a daemon for the Operating System
  my $daemon = Any::Daemon->new(@os_opts);

  # Start logging to syslog (see Log::Report::Dispatcher)
  dispatcher SYSLOG => syslog;

  # Run managing daemon


This module delivers the basic needs for any daemon on UNIX systems. There are other standard daemon implementations available on CPAN, with as main common difference that this module is not dedicated to a specific task. By using Log::Report, you can easily redirect error reports to any logging mechanism you like.

The code for this module is in use for many different daemons, some with heavy load (a few dozen requests per second) Have a look in the examples directory! Also, you may like Any::Daemon::HTTP



Any::Daemon-><B>newB>(%options) With new() you provide the operating system integration %options, where run() gets the activity related parameters: the real action.

Be warned that the user, group, and workdir will not immediately be effected: delayed until run().

 -Option  --Default
  group     undef
  pid_file  undef
  user      undef
  workdir   current working directory

group => GID|GROUPNAME Change to this group (when started as root)
pid_file => FILENAME
user => UID|USERNAME Change to this user (when started as root) If you want to run your daemon as root, then explicitly specify that with this option, to avoid a warning.
workdir => DIRECTORY Change DIRECTORY so temporary files and such are not written in the random directory where the daemon got started.

If the directory does not exist yet, it will be created with mode 0700 when the daemon object is initialized. We only move to that directory when the daemon is run. The working directory does not get cleaned when the daemon stops.


$obj-><B>workdirB>() [0.90] assigned working directory of the daemon in the file-system.


$obj-><B>runB>(%options) The run method gets the activity related parameters.

 -Option     --Default
  background   <true>
  child_died   spawn new childs
  child_task   warn only
  kill_childs  send sigterm
  max_childs   10
  reconfigure  ignore

background => BOOLEAN Run the managing daemon in the background. During testing, it is prefered to run the daemon in the foreground, to be able to stop the daemon with Crtl-C and to see errors directly on the screen in stead of only in some syslog file.
child_died => CODE The child_died routine handles dieing kids and the restart of new ones. It gets two parameters: the maximum number of childs plus the task to perform per kid.
child_task => CODE The CODE will be run for each child which is started, also when they are started later on. If the task is not specified, only a warning is produced. This may be useful when you start implementing the daemon: you do not need to care about the task to perform yet.

The returned value of thise CODE is used as exit code of the child process, where zero means ’ok’.

kill_childs => CODE The CODE terminates all running children, maybe to start new ones, maybe to terminate the whole daemon.
max_childs => INTEGER The maximum (is usual) number of childs to run.
reconfigure => CODE The CODE is run when a SIGHUP is received; signal 1 is used by most daemons as trigger for reconfiguration.


This module is part of Any-Daemon distribution version 0.94, built on March 10, 2014. Website: All modules in this suite: Any::Daemon, IOMux, and IOMux::HTTP.

Please post questions or ideas to


Copyrights 2011-2014 by [Mark Overmeer]. For other contributors see ChangeLog.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See

Search for    or go to Top of page |  Section 3 |  Main Index

perl v5.20.3 ANY::DAEMON (3) 2014-03-10

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.