<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: daemon code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 09:29:24 GMT</pubDate>
    <description>DZone Snippets: daemon code</description>
    <item>
      <title>Daemonize a Ruby process</title>
      <link>http://snippets.dzone.com/posts/show/3646</link>
      <description>// description of your code here&lt;br /&gt;from : http://scie.nti.st/2006/12/15/daemonize-a-ruby-process&lt;br /&gt;Here's a neat thing I found. I needed a small bit of Ruby code to run continuously in the background, but because of how Capistrano can't seem to work well with "nohup" and "&amp;" (background job), my ruby script itself needed to be able to fork and detach from the terminal. Here's how you do it: &lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;pid = fork do&lt;br /&gt;  Signal.trap('HUP', 'IGNORE') # Don't die upon logout&lt;br /&gt;&lt;br /&gt;  loop do&lt;br /&gt;&lt;br /&gt;    // Some code&lt;br /&gt;&lt;br /&gt;    sleep 60&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Process.detach(pid)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 08 Mar 2007 09:42:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3646</guid>
      <author>Mickael (Mickael)</author>
    </item>
    <item>
      <title>PyS60 - DaemonS60</title>
      <link>http://snippets.dzone.com/posts/show/3178</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import appuifw&lt;br /&gt;import e32&lt;br /&gt;import thread&lt;br /&gt;&lt;br /&gt;lock = e32.Ao_lock()&lt;br /&gt;lockTHR = thread.allocate_lock()&lt;br /&gt;&lt;br /&gt;###### Sostituisci questa funzione con quello che vuoi fare eseguire&lt;br /&gt;i = 0&lt;br /&gt;def funzDaemon():&lt;br /&gt;	global i&lt;br /&gt;	while(1):&lt;br /&gt;		lockTHR.acquire()&lt;br /&gt;		e32.ao_sleep(1)&lt;br /&gt;		open('E:\\Others\\tmp.txt', 'a').write(str(i)+"\n")&lt;br /&gt;		i+=1&lt;br /&gt;		lockTHR.release()&lt;br /&gt;####################################################################&lt;br /&gt;&lt;br /&gt;appuifw.app.title = u'DaemonS60'&lt;br /&gt;appuifw.app.exit_key_handler = lambda:lock.signal()&lt;br /&gt;&lt;br /&gt;print 'DaemonS60 - Start'&lt;br /&gt;&lt;br /&gt;thread.start_new_thread(funzDaemon, ())&lt;br /&gt;&lt;br /&gt;lock.wait()&lt;br /&gt;&lt;br /&gt;print 'DaemonS60 - Stop'&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 19 Dec 2006 23:56:06 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3178</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Linux - Example Crontab</title>
      <link>http://snippets.dzone.com/posts/show/3125</link>
      <description>// Esegue lo script ogni ora&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;// Minute(0-59) Hours(0-23) DayOfMonth(1-31) Month(1-12) DayOfWeek(0-6/Sun-Sat) Command&lt;br /&gt;* */1 * * * script.sh&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 11 Dec 2006 04:33:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3125</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Daemonize a Ruby process</title>
      <link>http://snippets.dzone.com/posts/show/3107</link>
      <description>Here's a neat thing I found. I needed a small bit of Ruby code to run continuously in the background, but because of how Capistrano can't seem to work well with "nohup" and "&amp;" (background job), my ruby script itself needed to be able to fork and detach from the terminal. Here's how you do it:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/ruby&lt;br /&gt;&lt;br /&gt;pid = fork do&lt;br /&gt;  loop do&lt;br /&gt;&lt;br /&gt;    // Some code&lt;br /&gt;&lt;br /&gt;    sleep 1.minute&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Process.detach(pid)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In my case, I just needed some code to run each minute, but it is part of a Rails app, so I didn't just want to start it with cron every minute (Rails loading is expensive). Neat eh?</description>
      <pubDate>Fri, 08 Dec 2006 12:52:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3107</guid>
      <author>garrydolley (Garry Dolley)</author>
    </item>
    <item>
      <title>Fix Content-Length header on UTF8 with HTTP::Daemon in Perl</title>
      <link>http://snippets.dzone.com/posts/show/2283</link>
      <description>&lt;code&gt;&lt;br /&gt;It seems that HTTP/Daemon.pm is bogus when it calculate&lt;br /&gt;the header 'Content-Length' when the data contains UTF8 data .&lt;br /&gt;&lt;br /&gt;In attachement a patch , to calculate the length in bytes&lt;br /&gt;of the data .&lt;br /&gt;&lt;br /&gt;-- &lt;br /&gt;     ____________________________________________________________&lt;br /&gt;    / Erwan MAS                                                 /\&lt;br /&gt;   | mailto:[EMAIL PROTECTED]                                   |_/&lt;br /&gt;___|________________________________________________________   |&lt;br /&gt;\___________________________________________________________\__/&lt;br /&gt;&lt;br /&gt;--- Daemon.pm.orig      2004-12-11 16:13:22.000000000 +0100&lt;br /&gt;+++ Daemon.pm   2006-05-02 22:53:33.660393022 +0200&lt;br /&gt;@@ -436,7 +436,7 @@&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        elsif (length($content)) {&lt;br /&gt;-           $res-&gt;header("Content-Length" =&gt; length($content));&lt;br /&gt;+           $res-&gt;header("Content-Length" =&gt; bytes::length($content));&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;            $self-&gt;force_last_request;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 18 Jul 2006 01:53:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2283</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Ruby Daemon Module</title>
      <link>http://snippets.dzone.com/posts/show/2265</link>
      <description>The following code lets you implement a daemon very easily, and also lets you write cleanup code.&lt;br /&gt;&lt;br /&gt;Update: I made some small changes to make it look slightly better.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'fileutils'&lt;br /&gt;&lt;br /&gt;module Daemon&lt;br /&gt;  WorkingDirectory = File.expand_path(File.dirname(__FILE__))  &lt;br /&gt;&lt;br /&gt;  class Base&lt;br /&gt;    def self.pid_fn&lt;br /&gt;      File.join(WorkingDirectory, "#{name}.pid")&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.daemonize&lt;br /&gt;      Controller.daemonize(self)&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  module PidFile&lt;br /&gt;    def self.store(daemon, pid)&lt;br /&gt;      File.open(daemon.pid_fn, 'w') {|f| f &lt;&lt; pid}&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.recall(daemon)&lt;br /&gt;      IO.read(daemon.pid_fn).to_i rescue nil&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  module Controller&lt;br /&gt;    def self.daemonize(daemon)&lt;br /&gt;      case !ARGV.empty? &amp;&amp; ARGV[0]&lt;br /&gt;      when 'start'&lt;br /&gt;        start(daemon)&lt;br /&gt;      when 'stop'&lt;br /&gt;        stop(daemon)&lt;br /&gt;      when 'restart'&lt;br /&gt;        stop(daemon)&lt;br /&gt;        start(daemon)&lt;br /&gt;      else&lt;br /&gt;        puts "Invalid command. Please specify start, stop or restart."&lt;br /&gt;        exit&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    &lt;br /&gt;    def self.start(daemon)&lt;br /&gt;      fork do&lt;br /&gt;        Process.setsid&lt;br /&gt;        exit if fork&lt;br /&gt;        PidFile.store(daemon, Process.pid)&lt;br /&gt;        Dir.chdir WorkingDirectory&lt;br /&gt;        File.umask 0000&lt;br /&gt;        STDIN.reopen "/dev/null"&lt;br /&gt;        STDOUT.reopen "/dev/null", "a"&lt;br /&gt;        STDERR.reopen STDOUT&lt;br /&gt;        trap("TERM") {daemon.stop; exit}&lt;br /&gt;        daemon.start&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;  &lt;br /&gt;    def self.stop(daemon)&lt;br /&gt;      if !File.file?(daemon.pid_fn)&lt;br /&gt;        puts "Pid file not found. Is the daemon started?"&lt;br /&gt;        exit&lt;br /&gt;      end&lt;br /&gt;      pid = PidFile.recall(daemon)&lt;br /&gt;      FileUtils.rm(daemon.pid_fn)&lt;br /&gt;      pid &amp;&amp; Process.kill("TERM", pid)&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;To use it, you can do something like the following:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Counter &lt; Daemon::Base&lt;br /&gt;  def self.start&lt;br /&gt;    @a = 0&lt;br /&gt;    loop do&lt;br /&gt;      @a += 1&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def self.stop&lt;br /&gt;    File.open('result', 'w') {|f| f.puts "a = #{@a}"}&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Counter.daemonize&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 10 Jul 2006 15:02:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2265</guid>
      <author>ciconia (Sharon Rosner)</author>
    </item>
    <item>
      <title>C - create Process Daemon</title>
      <link>http://snippets.dzone.com/posts/show/1538</link>
      <description>// Create a process Daemon&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#include &lt;stdio.h&gt;&lt;br /&gt;#include &lt;unistd.h&gt;&lt;br /&gt;&lt;br /&gt;#include &lt;sys/types.h&gt;&lt;br /&gt;#include &lt;sys/stat.h&gt;&lt;br /&gt;&lt;br /&gt;int main(int argc, char *argv[])&lt;br /&gt;{&lt;br /&gt;	/*&lt;br /&gt;	 * Funzione che mi crea un demone&lt;br /&gt;	 */&lt;br /&gt;	&lt;br /&gt;	int pid;&lt;br /&gt;	&lt;br /&gt;	// create - fork 1&lt;br /&gt;	if(fork()) return 0;&lt;br /&gt;&lt;br /&gt;	// it separates the son from the father&lt;br /&gt;	chdir("/");&lt;br /&gt;	setsid();&lt;br /&gt;	umask(0);&lt;br /&gt;&lt;br /&gt;	// create - fork 2&lt;br /&gt;	pid = fork();&lt;br /&gt;&lt;br /&gt;	if(pid)&lt;br /&gt;	{&lt;br /&gt;		printf("Daemon: %d\n", pid);&lt;br /&gt;		return 0;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	/****** Codice da eseguire ********/	&lt;br /&gt;	FILE *f;&lt;br /&gt;&lt;br /&gt;	f=fopen("/tmp/coa.log", "w");&lt;br /&gt;	&lt;br /&gt;	while(1)&lt;br /&gt;	{&lt;br /&gt;		fprintf(f, "ciao\n");&lt;br /&gt;		fflush(f);&lt;br /&gt;		sleep(2);&lt;br /&gt;	}&lt;br /&gt;	/**********************************/&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 21 Feb 2006 02:05:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1538</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Python - create daemon</title>
      <link>http://snippets.dzone.com/posts/show/1532</link>
      <description>// Questa funzione permette di creare un demone in python&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def createDaemon():&lt;br /&gt;	'''Funzione che crea un demone per eseguire un determinato programma...'''&lt;br /&gt;	&lt;br /&gt;	import os&lt;br /&gt;	&lt;br /&gt;	# create - fork 1&lt;br /&gt;	try:&lt;br /&gt;		if os.fork() &gt; 0: os._exit(0) # exit father...&lt;br /&gt;	except OSError, error:&lt;br /&gt;		print 'fork #1 failed: %d (%s)' % (error.errno, error.strerror)&lt;br /&gt;		os._exit(1)&lt;br /&gt;&lt;br /&gt;	# it separates the son from the father&lt;br /&gt;	os.chdir('/')&lt;br /&gt;	os.setsid()&lt;br /&gt;	os.umask(0)&lt;br /&gt;&lt;br /&gt;	# create - fork 2&lt;br /&gt;	try:&lt;br /&gt;		pid = os.fork()&lt;br /&gt;		if pid &gt; 0:&lt;br /&gt;			print 'Daemon PID %d' % pid&lt;br /&gt;			os._exit(0)&lt;br /&gt;	except OSError, error:&lt;br /&gt;		print 'fork #2 failed: %d (%s)' % (error.errno, error.strerror)&lt;br /&gt;		os._exit(1)&lt;br /&gt;&lt;br /&gt;	funzioneDemo() # function demo&lt;br /&gt;	&lt;br /&gt;def funzioneDemo():&lt;br /&gt;&lt;br /&gt;	import time&lt;br /&gt;&lt;br /&gt;	fd = open('/tmp/demone.log', 'w')&lt;br /&gt;	while True:&lt;br /&gt;		fd.write(time.ctime()+'\n')&lt;br /&gt;		fd.flush()&lt;br /&gt;		time.sleep(2)&lt;br /&gt;	fd.close()&lt;br /&gt;	&lt;br /&gt;if __name__ == '__main__':&lt;br /&gt;&lt;br /&gt;	createDaemon()&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 20 Feb 2006 05:10:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1532</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Pre-forking HTTP daemon in Perl</title>
      <link>http://snippets.dzone.com/posts/show/257</link>
      <description>Version 2.. it had issues with zombie / defunct processes on Linux. This is significantly more stable, and I'm currently serving 300,000+ requests a day on something based off of this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;#!/usr/bin/perl&lt;br /&gt;&lt;br /&gt;# Basic pre-forking HTTP daemon - version 2&lt;br /&gt;# By Peter Cooper - http://www.petercooper.co.uk/&lt;br /&gt;#&lt;br /&gt;# Inspiration and various rehashed snippetsof code from the Perl &lt;br /&gt;# cfdaemon engine - http://perl-cfd.sourceforge.net/&lt;br /&gt;#&lt;br /&gt;# You can switch out HTTP::Daemon and make it a pre-forking daemonized &lt;br /&gt;# 'anything' if you wish..&lt;br /&gt;&lt;br /&gt;use HTTP::Daemon;&lt;br /&gt;use HTTP::Status;&lt;br /&gt;use CGI;&lt;br /&gt;use POSIX;&lt;br /&gt;&lt;br /&gt;my $totalChildren = 15;				# Number of listening children to keep alive&lt;br /&gt;my $childLifetime = 10;			# Let each child serve up to this many requests&lt;br /&gt;my $logFile = "/tmp/daemon.log";	# Log requests and errors to this file&lt;br /&gt;my %children;							# Store pids of children&lt;br /&gt;my $children = 0;						# Store number of currently active children&lt;br /&gt;&lt;br /&gt;&amp;daemonize;								# Daemonize the parent&lt;br /&gt;&lt;br /&gt;my $d = HTTP::Daemon-&gt;new( LocalPort =&gt; 1981, LocalAddr =&gt; '127.0.0.1', Reuse =&gt; 1, Timeout =&gt; 180 ) || die "Cannot create socket: $!\n";&lt;br /&gt;&lt;br /&gt;warn ("master is ", $d-&gt;url);&lt;br /&gt;&lt;br /&gt;&amp;spawnChildren;&lt;br /&gt;&amp;keepTicking;&lt;br /&gt;exit;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# spawnChildren - initial process to spawn the right number of children&lt;br /&gt;&lt;br /&gt;sub spawnChildren {&lt;br /&gt;	for (1..$totalChildren) {&lt;br /&gt;		&amp;newChild();&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# keepTicking - a never ending loop for the parent process which just monitors&lt;br /&gt;# dying children and generates new ones&lt;br /&gt;&lt;br /&gt;sub keepTicking {&lt;br /&gt;	while ( 1 ) {&lt;br /&gt;		sleep;&lt;br /&gt;	  	for (my $i = $children; $i &lt; $totalChildren; $i++ ) {&lt;br /&gt;		  &amp;newChild();&lt;br /&gt;		}&lt;br /&gt;	};&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# newChild - a forked child process that actually does some work&lt;br /&gt;&lt;br /&gt;sub newChild {&lt;br /&gt;	my $pid;&lt;br /&gt;	my $sigset = POSIX::SigSet-&gt;new(SIGINT);				# Delay any interruptions!&lt;br /&gt;   sigprocmask(SIG_BLOCK, $sigset) or die "Can't block SIGINT for fork: $!";&lt;br /&gt;   die "Cannot fork child: $!\n" unless defined ($pid = fork);&lt;br /&gt;	if ($pid) {&lt;br /&gt;		$children{$pid} = 1;										# Report a child is using this pid&lt;br /&gt;		$children++;												# Increase the child count&lt;br /&gt;		warn "forked new child, we now have $children children";&lt;br /&gt;		return;														# Head back to wait around&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	my $i;&lt;br /&gt;	while ($i &lt; $childLifetime) {				# Loop for $childLifetime requests&lt;br /&gt;		$i++;&lt;br /&gt;		my $c = $d-&gt;accept or last;							# Accept a request, or if timed out.. die early&lt;br /&gt;		$c-&gt;autoflush(1);&lt;br /&gt;		logMessage ("connect:". $c-&gt;peerhost . "\n");	# We've accepted a connection!&lt;br /&gt;     	my $r = $c-&gt;get_request(1) or last;					# Get the request. If it fails, die early&lt;br /&gt;&lt;br /&gt;		# Insert your own logic code here. The request is in $r&lt;br /&gt;		# What we do here is check if the method is not GET, if so.. send back a 403.&lt;br /&gt;&lt;br /&gt;		my $url = $r-&gt;url;&lt;br /&gt;		$url =~ s/^\///g;&lt;br /&gt;&lt;br /&gt;     	if ($r-&gt;method ne 'GET') { &lt;br /&gt;			$c-&gt;send_error(RC_FORBIDDEN); &lt;br /&gt;			logMessage ($c-&gt;peerhost . " made weird request\n"); &lt;br /&gt;			redo;&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		my $response = HTTP::Response-&gt;new(200);			# Put together a response&lt;br /&gt;		logMessage ($c-&gt;peerhost . " " . $d-&gt;url . $url . "\n");	&lt;br /&gt;		$response-&gt;content("&lt;html&gt;&lt;body&gt;The daemon works! This child has served $i requests.&lt;/body&gt;&lt;/html&gt;");&lt;br /&gt;#				$response-&gt;content("document.write('OK $i&lt;br \/&gt;');");&lt;br /&gt;		$response-&gt;header("Content-Type" =&gt; "text/html");&lt;br /&gt;		$c-&gt;send_response($response);							# Send back a basic response&lt;br /&gt;		&lt;br /&gt;		logMessage ("disconnect:" . $c-&gt;peerhost . " - ct[$i]\n");		# Log the end of the request&lt;br /&gt;      $c-&gt;close;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	warn "child terminated after $i requests";&lt;br /&gt;	exit;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# REAPER - a reaper of dead children/zombies with exit codes to spare&lt;br /&gt;&lt;br /&gt;sub REAPER {                            &lt;br /&gt;	my $stiff;&lt;br /&gt;	while (($stiff = waitpid(-1, &amp;WNOHANG)) &gt; 0) {&lt;br /&gt;		warn ("child $stiff terminated -- status $?");&lt;br /&gt;		$children--;&lt;br /&gt;		$children{$stiff};&lt;br /&gt;	}&lt;br /&gt;	$SIG{CHLD} = \&amp;REAPER;&lt;br /&gt;}        &lt;br /&gt;&lt;br /&gt;# daemonize - daemonize the parent/control app&lt;br /&gt;&lt;br /&gt;sub daemonize {&lt;br /&gt;	my $pid = fork;												# Fork off the main process&lt;br /&gt;	defined ($pid) or die "Cannot start daemon: $!"; 	# If no PID is defined, the daemon failed to start&lt;br /&gt;	print "Parent daemon running.\n" if $pid;				# If we have a PID, the parent daemonized okay&lt;br /&gt;	exit if $pid;													# Return control to the user&lt;br /&gt;&lt;br /&gt;   # Now we're a daemonized parent process!&lt;br /&gt;&lt;br /&gt;	POSIX::setsid();												# Become a session leader&lt;br /&gt;&lt;br /&gt;	close (STDOUT);												# Close file handles to detach from any terminals&lt;br /&gt;	close (STDIN);&lt;br /&gt;	close (STDERR);&lt;br /&gt;&lt;br /&gt;	# Set up signals we want to catch. Let's log warnings, fatal errors, and catch hangups and dying children&lt;br /&gt;&lt;br /&gt;	$SIG{__WARN__} = sub {&lt;br /&gt;			&amp;logMessage ("NOTE! " . join(" ", @_));&lt;br /&gt;	};&lt;br /&gt;	&lt;br /&gt;	$SIG{__DIE__} = sub { &lt;br /&gt;		&amp;logMessage ("FATAL! " . join(" ", @_));&lt;br /&gt;		exit;&lt;br /&gt;	};&lt;br /&gt;&lt;br /&gt;	$SIG{HUP} = $SIG{INT} = $SIG{TERM} = sub {			# Any sort of death trigger results in instant death of all&lt;br /&gt;	  my $sig = shift;&lt;br /&gt;	  $SIG{$sig} = 'IGNORE';&lt;br /&gt;	  kill 'INT' =&gt; keys %children;&lt;br /&gt;	  die "killed by $sig\n";&lt;br /&gt;	  exit;&lt;br /&gt;	};	&lt;br /&gt;	&lt;br /&gt;	$SIG{CHLD} = \&amp;REAPER;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;# logMessage - append messages to a log file. messy, but it works for now.&lt;br /&gt;&lt;br /&gt;sub logMessage {&lt;br /&gt;	my $message = shift;&lt;br /&gt;	(my $sec, my $min, my $hour, my $mday, my $mon, my $year) = gmtime();&lt;br /&gt;	$mon++;&lt;br /&gt;	$mon = sprintf("%0.2d", $mon);&lt;br /&gt;	$mday = sprintf("%0.2d", $mday);&lt;br /&gt;	$hour = sprintf("%0.2d", $hour);&lt;br /&gt;	$min = sprintf("%0.2d", $min);&lt;br /&gt;	$sec = sprintf("%0.2d", $sec);&lt;br /&gt;	$year += 1900;&lt;br /&gt;	my $time = qq{$year/$mon/$mday $hour:$min:$sec};&lt;br /&gt;	open (FH, "&gt;&gt;" . $logFile);&lt;br /&gt;	print FH $time . " - " . $message;&lt;br /&gt;	close (FH);&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Thu, 05 May 2005 23:03:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/257</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
