On Thu, 2 Sep 2004, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: ruby-dev summary 24054-24170" > on Thu, 2 Sep 2004 23:16:12 +0900, Ara.T.Howard / noaa.gov writes: > > |i always use a double fork - you feel this is enough though? > > Since the calling process dies in the daemon(), there's no need for > double fork. > > matz. here's a snip from some code i'm running as we speak - i stole the code from open3, which seemed to agree with steven's book (if memory serves me): def daemon #{{{ if opt_daemon fork do Process.setsid fork do Dir.chdir(Util.realpath('~')) open('/dev/null','r+') do |f| STDIN.reopen f STDOUT.reopen f STDERR.reopen f end daemon_wrap{ yield } exit EXIT_SUCCESS end exit! end exit! else daemon_wrap{ yield } exit EXIT_SUCCESS end #}}} end def daemon_wrap #{{{ begin yield rescue Exception => e unless SystemExit === e or opt_quiet fatal{ e } rescue nil end exit EXIT_FAILURE end #}}} end i guess open3 needs it (the 2x fork) because there the calling process does __not__ exit, in my code however, it does. so the double fork is needed to 'spawn a daemon process' and a single fork is o.k. to 'become a daemon'. sound correct? it seems like there is never any harm in having a double fork though, is there? cheers. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | A flower falls, even though we love it; | and a weed grows, even though we do not love it. | --Dogen ===============================================================================