mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00

* .document: Add prelude.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@27093 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
36 lines
962 B
Ruby
36 lines
962 B
Ruby
# currently empty
|
|
|
|
module Process
|
|
# call-seq:
|
|
# Process.daemon() => 0
|
|
# Process.daemon(nochdir=nil,noclose=nil) => 0
|
|
#
|
|
# Detach the process from controlling terminal and run in
|
|
# the background as system daemon. Unless the argument
|
|
# nochdir is true (i.e. non false), it changes the current
|
|
# working directory to the root ("/"). Unless the argument
|
|
# noclose is true, daemon() will redirect standard input,
|
|
# standard output and standard error to /dev/null.
|
|
# Return zero on success, or raise one of Errno::*.
|
|
def self.daemon(nochdir = nil, noclose = nil)
|
|
if $SAFE >= 2
|
|
raise SecurityError, "Insecure operation `%s' at level %d", __method__, $SAFE
|
|
end
|
|
|
|
fork && exit!(0)
|
|
|
|
Process.setsid()
|
|
|
|
fork && exit!(0)
|
|
|
|
Dir.chdir('/') unless nochdir
|
|
|
|
File.open('/dev/null', 'r+') { |f|
|
|
STDIN.reopen(f)
|
|
STDOUT.reopen(f)
|
|
STDERR.reopen(f)
|
|
} unless noclose
|
|
|
|
return 0
|
|
end
|
|
end
|