Project

General

Profile

Backport #7720 ยป daemon.rb

benweint (Ben Weintraub), 01/22/2013 02:33 AM

 
1
#!/usr/bin/env ruby
2

    
3
Thread.new do
4
  loop do
5
    puts "background thread in #{$$} woke"
6
    sleep(1)
7
  end
8
end
9

    
10
sleep(2)
11

    
12
if ARGV[0] == 'fork'
13
  puts "#{$$} forking"
14
  Process.fork
15
else
16
  puts "#{$$} daemonizing"
17
  Process.daemon(true, true)
18
end
19

    
20
puts "#{$$} exiting with #{Thread.list.size} Ruby threads"