Module: Process

Defined in:
lib/gri/util_daemon.rb

Instance Method Summary collapse

Instance Method Details

#daemon(nochdir = nil, noclose = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/gri/util_daemon.rb', line 4

def daemon(nochdir = nil, noclose = nil)
  exit!(0) if Process.fork
  Process.setsid
  exit!(0) if Process.fork
  Dir.chdir("/") unless nochdir
  unless noclose
    #File.umask(0)
    STDIN.reopen("/dev/null", "r")
    STDOUT.reopen("/dev/null", "w")
    STDERR.reopen("/dev/null", "w")
  end
  0
end