### Home Classes Methods

### In Files

- lib/facets/process/daemon.rb

### Methods

- ::daemon

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# Process

### Public Class Methods

daemon(nochdir=nil, noclose=nil) click to toggle source

Turns the current script into a daemon process that detaches from the console. It can be shut down with a TERM signal.

CREDIT: David Heinemeier Hansson

    # File lib/facets/process/daemon.rb, line 9
    def self.daemon(nochdir=nil, noclose=nil)
      exit if fork # Parent exits, child continues.
      Process.setsid # Become session leader.
      exit if fork # Zap session leader. See [1].

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

      File.umask 0000 # Ensure sensible umask. Adjust as needed.

      unless noclose
        STDIN.reopen "/dev/null" # Free file descriptors and
        STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
        STDERR.reopen '/dev/null', 'a'
      end

      trap("TERM") { exit }

      return 0
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.