forkしてPIDファイルを作る

あってるのやら…

def run_as_daemon(gdbm_srv, pidfile)
  fork {
    Process.setsid
    open(pidfile, 'w') {|f| f << Process.pid } if pidfile
    trap(:INT) { gdbm_srv.shutdown; exit! 0 }
    trap(:TERM) { gdbm_srv.shutdown; exit! 0 }
    File.open('/dev/null', 'r+') {|f|
      STDIN.reopen f; STDOUT.reopen f; STDERR.reopen f
    }
    gdbm_srv.start
  }
  exit! 0
end