123456789_123456789_123456789_123456789_123456789_

Module: Process

Relationships & Source Files
Defined in: lib/puma/daemon_ext.rb

Class Method Summary

Class Method Details

.daemon(nochdir = false, noclose = false)

[ GitHub ]

  
# File 'lib/puma/daemon_ext.rb', line 14

def self.daemon(nochdir=false, noclose=false)
  exit if fork                     # Parent exits, child continues.

  Process.setsid                   # Become session leader.

  exit if fork                     # Zap session leader. See [1].

  Dir.chdir "/" unless nochdir     # Release old working directory.

  if !noclose
    STDIN.reopen File.open("/dev/null", "r")

    null_out = File.open "/dev/null", "w"
    STDOUT.reopen null_out
    STDERR.reopen null_out
  end

  0
end