DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Daemonize A Ruby Process
Neat separation of responsibilities between fork/process stuff and actual app
#!/usr/bin/ruby
daemonize do
worker = Resque::Worker.new(*queues)
worker.work
end
def daemonize &block
child = fork
if child.nil? # is child
$stdout.close
$stdout = open("/dev/null")
$stdin.close
trap('HUP', 'IGNORE')
block.call
else # is parent
Process.detach child
end
end





