Hi,
	
In message "[ruby-talk:8285] Re: New to Ruby"
    on 00/12/30, Dave Thomas <Dave / PragmaticProgrammer.com> writes:

>Yes you could, although a true daemon does a few extra things too to
>disassociate it from the controlling terminal and session.

Here is an example. 

------------------------------------------------------------
#!/usr/bin/env/ruby
# daytime-server.rb
# A simple DAYTIME(RFC 867) server

require "socket"

def daemon
  fork do
    Process::setsid
    fork do
      Dir::chdir("/")
      File::umask(0)
      STDIN.close; STDOUT.close; STDERR.close
      yield
    end
  end
  exit!
end

host = ARGV[0] || "localhost"
port = ARGV[1] || 10000   # but well-known port is 13

u = UDPSocket.open
u.bind(host, port)
puts "daytime: start on #{host}:#{port}"
daemon do
  loop do
    _, addr = u.recvfrom(256, 0)
    u.send(Time.now.inspect + "\r\n",
           0, addr[2], addr[1])
  end
end
------------------------------------------------------------

The deamon method appeared in our serial article ``Intenet programming
with Ruby'' on OpenDesign and was originally written by TOKI san,
http://www.freedom.ne.jp/toki/ruby.html

See also ``UNIX Programming Frequently Asked Questions - 1.7 How do I
get my program to act like a daemon?'', 
http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16

-- Gotoken