Module: Process

Defined in:
lib/pmux/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
# File 'lib/pmux/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
    STDIN.reopen("/dev/null", "r")
    STDOUT.reopen("/dev/null", "w")
    STDERR.reopen("/dev/null", "w")
  end
  0
end