From: Jim Freeze Date: 2005-11-08T02:06:26+09:00 Subject: Re: Daemons written in ruby... A while back there was some discussion about daemons. As I recall, there was a list of 5 things that one needed to do to have a 'correct' daemon, but I never saw it in Ruby code. Below is what I have used, and it has worked for my needs, but it may have problems in some environments because I am missing 4 of the 5 requirements. I would love to see this standardized and put in the stdlib, or made into a gem. def start_daemon(do_print = false) if (child_pid = fork) STDERR.puts "PID #{child_pid}" if do_print exit end Process.setsid end def run # daemonize the process start_daemon end On 11/7/05, Steve [RubyTalk] wrote: > I've written a simple daemon as a ruby script... it writes all > interesting output to a log file and is intended to be a long-running > process as opposed to a program which executes only while a user is > logged in. > > In C I'd have closed stdin, stdout and stderr; dissociate my process > from its parent then called fork in order to return 0 indicate > successfully starting the daemon. > > What is the best way to achieve this in Ruby? I can achieve the end > result I want using nohup, but I'm sure there must be a neater way. > -- Jim Freeze